Input 12345 output 1 2 3 4 5

Create a program which will ask the user to input 5 digit number and display the numbers between spaces.

input:
12345

output:
1 2 3 4 5

Here's the tip:

12345 - 2345 = 10000/10000 = 1
2345 - 345 = 2000/1000 = 2
345 - 45 = 300/100 = 3
45 - 5 = 40/10 = 4
45 - 40 = 5

You will notice that you need to subtract the 12345 to 2345. 2345 is the digit except for the 1st digit number. How to get it?

12345%10000 = 2345

its like 12345/10000 = 1.2345

This % will get the remainder.

Hope you get an idea from that.

If you have any comment, feel free to post.

2 comments:

jaems said...

nice one dah!!!

i will create a C program...XD

DarZ said...

nice two james carl!haha

Post a Comment