Please Fill out the Feedback Form for Code Radius

Sum of Digits : FLOW006 | CodeChef Solution

1 min read

 

Problem

You're given an integer N. Write a program to calculate the sum of all the digits of N.

Input Format

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

Output Format

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

Constraints

Sample

Input
12345
31203
2123
Output
15
9
8

Solution

cpp
#include <iostream> using namespace std; // Solution from : Code Radius [ https://radiuscode.blogspot.com/ ] int main() { int t; cin>>t; while(t--) { int n; cin>>n; int sum=0; while(n>0) { sum+=(n%10); n/=10; } cout<<sum<<"\n"; } return 0; }
Please First Try to Solve Problem by Yourself.

You may like these posts

  • Problem In a Chess match "a + b", each player has a clock which shows a minutes at the start and whenever a player makes a move, b seconds are added to this player's clock. Ti…
  •  ProblemYou're given an integer N. Write a program to calculate the sum of all the digits of N. Please Share this article... Input Format The first line contains an intege…
  •  ProblemChef has N slippers, L of which are left slippers and the rest are right slippers. Slippers must always be sold in pairs, where each pair contains one left and one rig…
  • Problem The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Ou…
  • Problem Gru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him…
  • Problem Chef has just started Programming, he is in first year of Engineering. Chef is reading about Relational Operators.Relational Operators are operators which check relati…

Post a Comment