sum of number

Solutions on MaxInterview for sum of number by the best coders in the world

showing results for - "sum of number"
Roberto
02 Sep 2017
1// Find Sum of Digits of a Number using for Loop
2// ----codescracker.com----
3
4#include<iostream>
5using namespace std;
6int main()
7{
8    int num, rem, sum;
9    cout<<"Enter the Number: ";
10    cin>>num;
11    for(sum=0; num>0; num=num/10)
12    {
13        rem = num%10;
14        sum = sum+rem;
15    }
16    cout<<"\nSum of Digits = "<<sum;
17    cout<<endl;
18    return 0;
19}