Monday, November 10, 2008

12345 into 1 2 3 4 5 output

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.

No comments: