Search & Find out

Sunday, December 6, 2009

SUM OF DIGITS



#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

0 comments:

Post a Comment

 

My Blog List

Term of Use