1. ## Separates digits

Hi all

anyone can give me any idea that how to do this using on single selection of if statment
"Write a program that inputs one five-digit number,separates the number into its individual digits and prints the digit seperately from one another.
like if input is 42139
the output

4 2 1 3 9"

any idea??

Best Regards

2. here is a "hint"
Use the "%" operator.
for example 98 % 10 gives u 8

that will help u separate the digits. put the whole thing in a loop, let the loop run as many times as the number of digits in ur original number.
at the end of the loop, U have all the digits.

3. failed....

4. Um, so I guess the problem is on line 42?
http://cboard.cprogramming.com/annou...t.php?f=4&a=39

5. how shud i separate the digit and with which digit i shud use for "%"

7. Code:
```#include<stdio.h>
#include<conio.h>
int main()
{
int a = 98;
int b = 10;
int rem;
int c;
clrscr();
rem = a % b;
c = rem + b;
printf(" : %d %d", c, rem);

return 0;

}```
it prints only for 9 n 8

it prints only for 9 n 8
: 18 8
Division is the other part of remainder after division. It is done with the / operator.

9. hmm thankx let me try
edit: where should i do i m completely feeling confused:S

10. Here's an example with 2 numbers :

19 = 1*10^1 + 9*10^0

19 % 10 = 9 --> Store this as the first digit (or last to print out)

floor(19/10) = 1 --> This is the result you'll now have to compare for your next digit

1 % 10 = 1 --> Store this as the second digit (or first to print out)

print out 1
print out 9.

There you go. Now do it for five numbers.

11. Extra large hint (I'm off to bed):
Code:
```#include<stdio.h>

int main()
{
int a = 123;
int div = a / 10;
int rem = a % 10;
printf("div = %d, rem = %d\n", div, rem);

a = div;
div = a / 10;
rem = a % 10;
printf("div = %d, rem = %d\n", div, rem);
return 0;
}

/* my output
div = 12, rem = 3
div = 1, rem = 2
*/```

12. thanks

13. Code:
```#include<stdio.h>
#include<conio.h>
int main()
{
int a;
int b = 10;
int rem,c;
clrscr();

printf("\n Enter a five digit number: ");
scanf("%d", &a);

rem = a / b;
c = a % b ;
printf("\n : %d", c);
a = rem;
rem = a / b;
c = a % b ;
printf(" %d", c);
a = rem;
rem = a / b;
c = a % b ;
printf(" %d", c);
a = rem;
rem = a / b;
c = a % b ;
printf(" %d", c);
a = rem;
rem = a / b;
c = a % b ;
printf(" %d", c);

return 0;

}```

for 42139 it gives a negative value and for 11111 it prints 1 1 1 1 1
edit: Sorry mates just read the integer types was just confused fully sorrryy once again