Sunday, December 6, 2009
SUM OF DIGITS
,
Author: Raviteja
|
Filed Under:
c++
|
#include "iostream.h"
#include "conio.h"
class digit
{
private:
long int n,N,q,r;
public:
digit ()
{
N = 0;
}
void accept ()
{
cout << "Enter a number: ";
cin >> n;
}
void cal ();
};
void digit :: cal ()
{
cout << "The sum of individual digits for " << n << " is: ";
for (; n>0; )
{
q = n/10;
r = n%10;
N += r;
n = q;
}
cout << N;
}
void main ()
{
clrscr ();
digit D;
cout<<"Welcome to find sum of the digits\n\n";
D.accept ();
D.cal ();
getch ();
}
Get the executable ( .exe ) file for this program..
Download
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment