Saturday, 10 March 2018

Sum of Digits

Sum of Digits



All submissions for this problem are available.
You're given an integer N. Write a program to calculate the sum of all the digits of N.

Input

The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.

Output

Calculate the sum of digits of N.

Constraints

  • 1  T  1000
  • 1  N  1000000

Example

Input
3 
12345
31203
2123
Output
15
9
8
 

solutions

  1. #include<stdio.h>
  2. int main()
  3. { int t,i,d;
  4. long n,s;
  5. scanf("%d",&t);
  6. for(i=0;i<t;i++)
  7. { s=0;
  8. scanf("%ld",&n);
  9. while(n!=0){
  10. d=n%10;
  11. s=s+d;
  12. n=n/10;
  13. }
  14. printf("%ld\n",s);
  15. }
  16. }

No comments:

Post a Comment

Reverse The Number

Reverse The Number All submissions for this problem are available. If an Integer   N , write a program to reverse the given number. ...