Splitting numbers

[b][red]This message was edited by Gazza29 at 2006-7-5 8:27:36[/red][/b][hr]
Using C, how do I input a five digit number, then split the number into its five seperate digits and print them on screen seperated by three spaces each?


Comments

  • : [b][red]This message was edited by Gazza29 at 2006-7-5 8:27:36[/red][/b][hr]
    : Using C, how do I input a five digit number, then split the number into its five seperate digits and print them on screen seperated by three spaces each?
    :
    :
    :

    input them as a string then you can easily print each character.
  • hey very simple,just input your number(five digit)
    and then you can use the logic of dividing the number by powers of 10(using power function in for loop i.e pow(10,i),and yo can easily get your all five numbers displayed.the other thing you should take care of is to keep on subtracting to get all the five numbers
    eg;
    12345

    x= 12345/10000 (where x is int)
    which will give x as 1 (first number displayed)
    next
    12345-10000 =2345
    2345/1000=2 (again as the variable is int so 2.345 will be stored as 2)
    like this all numbers can be dispayed.
    the solution that other guy gave uses arrays,but this uses only basic function as loop.thats it

  • Cheers people! It helps alot!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories