You are here:

C/How to separate one 5 digit number into individual digits

Advertisement


Zaiber wrote at 2009-09-11 06:04:33
If you happen to have had this problem in your class and needed a simpler answer that the one posted, then this is what I did on mine.



#include <stdio.h>



int main() {

   int num;

   

   printf("Please type your number: ");

   scanf("%d",&num);

   

   printf("%d   %d   %d   %d   %d",num/10000%10,num/1000%10,num/100%10,num/10%10,num%10);

   

   getchar();

   getchar();

   return 0;

}




Leo wrote at 2012-05-01 21:40:33
#include<stdio.h>



int main(void)



{

   int i1, i2, i3, i4, i5;



   printf("Please enter five number : ");



   scanf("%1d%1d%1d%1d%1d", &i1, &i2, &i3, &i4, &i5);



   printf("The number Entered is %d  %d  %d  %d  %d", i1, i2, i3, i4, i5);



   return 0;

}


Santiago wrote at 2012-12-07 23:10:51
#include <iostream>

#include <cmath>



using namespace std;



int main()

{

 int nro;

 int nroCifras=0;

 int temp;



 cout << "Insert number: ";

 cin >> nro;



 temp = nro;



 if(nro>0)

 {

     while(temp>0)

     {

         temp = temp/10;

         nroCifras++;

     }



     //Display 1 2 3 4 5

     for(int i=nroCifras-1;i>=0;i--)

     {

         cout << nro/int(pow(10,i)) << " ";

         nro = nro%int(pow(10,i));



     }

 }



 return 0;

}


Santiago wrote at 2012-12-07 23:12:06
#include <iostream>

#include <cmath>



using namespace std;



int main()

{

 int nro;

 int nroCifras=0;

 int temp;



 cout << "Insert number: ";

 cin >> nro;



 temp = nro;



 if(nro>0)

 {

     while(temp>0)

     {

         temp = temp/10;

         nroCifras++;

     }



     //Display 1 2 3 4 5

     for(int i=nroCifras-1;i>=0;i--)

     {

         cout << nro/int(pow(10,i)) << " ";

         nro = nro%int(pow(10,i));



     }

 }



 return 0;

}


C

All Answers


Answers by Expert:


Ask Experts

Volunteer


K.S Priya

Expertise

I am a computer researcher with more than 7 years of experience in C programming ,I can answer any type of questions regarding basic and advanced C programming.

Experience

Over 7 years

Organizations
St Joseph college Trichy

Education/Credentials
M.Sc Mphil

©2016 About.com. All rights reserved.