# 50 : C Program to Print Individual digits of entered number

Check out the complete list of c-programs : C Program List

We can make use of the program "Add sum of digits" or "Reverse of a number" that we have seen earlier to print digits of a number entered.

Logic :

``````while(number >=1 ) {

temp_var = number%10; //get unit place digit

// print out temp_var

number = number/10; //remove the units place

}```
```

Variables :

number : Datatype long : Holds value of number inputted by the user. %ld is the Format specifier for long's

temp_var : Datatype int : To hold temp values. %d is the Format specifier for int

i : Datatype int : Used to display digit place for a given number. %d is the Format specifier for int

``````
/*
* 1000+ C programs + tutorials
*
*
* 50_print_individual_digits_of_entered_number.c
*
*
*  Created on: Oct 22, 2014
*  Author: Code2care.org
*/

#include
//#include

void main() {

long number =0;
int temp_var = 0;
int i = 1;

//clrscr();

printf("C Program to Print Individual digits of a number :-");

printf("\n\n Enter a number (5 digits or more) : ");
scanf("%i", &number);

while(number >=1 ) {

temp_var = number%10; //get unit place digit

printf("\n\n Digit at %d place => %d  ",i,temp_var);
number = number/10; //remove the units place

i++;

}

//getch();

}```

```

• Output :

C Program to Print Individual digits of a number :-

Enter a number (5 digits or more) : 12345678

Digit at 1 place => 8

Digit at 2 place => 7

Digit at 3 place => 6

Digit at 4 place => 5

Digit at 5 place => 4

Digit at 6 place => 3

Digit at 7 place => 2

Digit at 8 place => 1

The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.