Saturday, April 5, 2014

C++ Program to find out the sum of digits of a number

C++ Program to find out the sum of digits of a number

#include<iostream.h>
class sumdig
{
int n,rem,rem1;
public:
void input()
{
cout<<"Enter the number\n";
cin>>n;
}
void calculation()
{
rem1=0;
while (n>0)
{
rem=n%10;
n=n/10;
rem1=rem1+rem;
}
}
void output()
{
cout<<"Sum of single digits is "<<rem1;
}
};
void main()
{
clrscr();
sumdig a;
a.input();
a.calculation();
a.output();
}

No comments:

Post a Comment