-
Language
C
-
Description
It separates ones, tens, hundreds, and thousands from a four-digit user input.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int four_digit_number, hundreds, ones, tens, thousands;
printf ("Enter the value of four digit number: ");
scanf ("%d", &four_digit_number);
(void) getchar ();
ones=four_digit_number%10;
tens=four_digit_number%100-ones;
hundreds=four_digit_number%1000-tens-ones;
thousands=(four_digit_number%10000-hundreds-tens-ones)/1000;
hundreds=hundreds/100;
tens=tens/10;
printf ("Value of hundreds: %d\n", hundreds);
printf ("Value of ones: %d\n", ones);
printf ("Value of tens: %d\n", tens);
printf ("Value of thousands: %d\n", thousands);
putchar ('\n');
system ("pause");
return EXIT_SUCCESS;
}
#include <stdlib.h>
int main (void)
{
int four_digit_number, hundreds, ones, tens, thousands;
printf ("Enter the value of four digit number: ");
scanf ("%d", &four_digit_number);
(void) getchar ();
ones=four_digit_number%10;
tens=four_digit_number%100-ones;
hundreds=four_digit_number%1000-tens-ones;
thousands=(four_digit_number%10000-hundreds-tens-ones)/1000;
hundreds=hundreds/100;
tens=tens/10;
printf ("Value of hundreds: %d\n", hundreds);
printf ("Value of ones: %d\n", ones);
printf ("Value of tens: %d\n", tens);
printf ("Value of thousands: %d\n", thousands);
putchar ('\n');
system ("pause");
return EXIT_SUCCESS;
}