Sum of Digits CodeChef Solution

Sum of Digits CodeChef Solution

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.

Example

Input
3 
12345
31203
2123
Output
15
9
8

Source Code:

#include <bits/stdc++.h>
using namespace std;

int main() {
int t; cin>>t;
while(t–){
int n,sum=0; cin>>n;
while(n){
sum+= n%10;
n/=10;
}
cout<<sum<<endl;
}
return 0;
}

Harsh

Hey Friends, Welcome to thetechbuddy. This blog is about technical or programming knowledge.

Leave a Reply