#include<iostream.h>
#include<conio.h>
class s_digits{
int num,sum;
public:
void input();
void calculate();
void output();
};
void s_digits::input()
{
cout<<"Enter your number:";
cin>>num;
}
void s_digits::calculate()
{
sum=0;
int r,n;
n=num;
while(n>0)
{
r=n%10;
sum+=r;
n=n/10;
}
}
void s_digits::output()
{
cout<<"The number entered is:"<<num;
cout<<"\nSum of its digits is:"<<sum;
}
void main()
{ clrscr();
s_digits ob;
ob.input();
ob.calculate();
ob.output();
getch();
}

No comments:
Post a Comment