Skip to content

Commit 42550f7

Browse files
Create sumofdigits.cpp
1 parent d0cc768 commit 42550f7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sumofdigits.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
5+
6+
int main()
7+
{
8+
9+
int t;
10+
scanf("%d", &t);
11+
for (int i; i < t; i++){
12+
int n;
13+
scanf("%d", &n);
14+
int ans = 0;
15+
while (n > 0){
16+
ans += n % 10;
17+
n /= 10;
18+
}
19+
printf("%d\n", ans);
20+
}
21+
22+
return 0;
23+
}

0 commit comments

Comments
 (0)