-
Notifications
You must be signed in to change notification settings - Fork 1
/
num_of_digits.c
51 lines (45 loc) · 1.05 KB
/
num_of_digits.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
int num_of_digits(int num)
{
int count = 0;
do{
count++;
num = num/10;
}while( num!= 0);
return count;
}
int reverse_of_digits(int num)
{
int reverse = 0;
while( num!= 0)
{
int rem = num % 10;
reverse = (reverse*10) + rem;
num = num/10;
}
return reverse;
}
int sum_of_digits(int num)
{
int sum = 0;
while( num!= 0)
{
int rem = num % 10;
sum = sum + rem;
num = num/10;
}
return sum;
}
int main()
{
printf("num of digits in number is %d\n", num_of_digits(0));
printf("num of digits in number is %d\n", num_of_digits(10));
printf("num of digits in number is %d\n", num_of_digits(123));
printf("reverse of number is %d\n", reverse_of_digits(0));
printf("reverse of number is %d\n", reverse_of_digits(10));
printf("reverse of number is %d\n", reverse_of_digits(123));
printf("sum of digits in number is %d\n", sum_of_digits(0));
printf("sum of digits in number is %d\n", sum_of_digits(10));
printf("sum of digits in number is %d\n", sum_of_digits(123));
return 0;
}