Splitting numbers - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Splitting numbers

Gazza29Gazza29 Posts: 8Member
[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 Posts: 9,765Member ✭✭✭
    : [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 Posts: 2Member
    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 Posts: 8Member
    Cheers people! It helps alot!
Sign In or Register to comment.