Write a program to find the sum of the digits

//this is program to find the sum of the digits
#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
int num,sum=0,rem=0;

//Accepting the value

cout<<"\n\nEnter the number: ";
cin>>num;

//Finding the sum of digits

while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}

//Displaying the sum

cout<<"\n\nThe sum of the digits entered number is "<<sum;

return 0;
}

Previous
Next Post »