repo.or.cz
/
letusc.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
move to repo.or.cz
[letusc.git]
/
ch1
/
exercises
/
ex7.c
blob
5940dd71db6178cc14ea3efa28b1b32dc77ae242
1
/*calculate the sum of digits in a 5 digit number*/
2
3
#include<stdio.h>
4
5
int
main
()
6
{
7
long
num
;
8
int
sum
;
9
10
11
printf
(
"Enter the five digit number: "
);
12
scanf
(
"%ld"
,&
num
);
13
14
sum
=
0
;
15
16
sum
=
sum
+ (
num
%
10
);
17
num
=
num
/
10
;
18
19
sum
=
sum
+(
num
%
10
);
20
num
=
num
/
10
;
21
22
sum
=
sum
+(
num
%
10
);
23
num
=
num
/
10
;
24
25
sum
=
sum
+(
num
%
10
);
26
num
=
num
/
10
;
27
28
sum
=
sum
+(
num
%
10
);
29
num
=
num
/
10
;
30
31
printf
(
"The sum is %d
\n
"
,
sum
);
32
33
return
0
;
34
35
36
}