Howdy, Stranger!

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

Categories

Splitting numbers

Gazza29Gazza29 Member Posts: 8
[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

  • stoberstober Member Posts: 9,765 ✭✭✭
    : [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.
  • jbondjbond Member Posts: 2
    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

  • Gazza29Gazza29 Member Posts: 8
    Cheers people! It helps alot!
Sign In or Register to comment.