Sum of Digits ||codechef||beginner solution ||programming info

Above picture is just a reference:-

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, the total number of testcases. Then follow T lines, each line contains an integer N.

Output

For each test case, calculate the sum of digits of N, and display it in a new line.

Constraints

  •  T  1000
  •  N  1000000

Example

Input
3 
12345
31203
2123
Output
15
9
8
SOLUTION USING C LANGUAGE:-
#include <stdio.h>
int main() {
	// your code goes here
	int t,i,n,r;
	scanf("%d\n",&t);
	for(i=0;i<t;i++)
	 {
	    r=0;
	    scanf("%d\n",&n);
	    while(n>0)
	    {
	    r=r+n%10;
        n=n/10;
     	}
	    printf("%d\n",r);
	}
	return 0;
}

Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support