chapter5
This commit is contained in:
18
DeitelC/Chapter5/sumOfDigits.c
Normal file
18
DeitelC/Chapter5/sumOfDigits.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int sumOfDigits(int);
|
||||
|
||||
int main(void) {
|
||||
int t = 7613;
|
||||
printf("%d\n", sumOfDigits(t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sumOfDigits(int num) {
|
||||
int result = 0;
|
||||
while (num > 0) {
|
||||
result += num % 10;
|
||||
num /= 10;
|
||||
}
|
||||
return result;
|
||||
}
|
Reference in New Issue
Block a user