Answers for "sum of number"

C++
0

sum of number

// Find Sum of Digits of a Number using for Loop
// ----codescracker.com----

#include<iostream>
using namespace std;
int main()
{
    int num, rem, sum;
    cout<<"Enter the Number: ";
    cin>>num;
    for(sum=0; num>0; num=num/10)
    {
        rem = num%10;
        sum = sum+rem;
    }
    cout<<"\nSum of Digits = "<<sum;
    cout<<endl;
    return 0;
}
Posted by: Guest on May-31-2021

Browse Popular Code Answers by Language