Pages

Ads 468x60px

Sunday, July 22, 2012

C++: Sum of a number's digits


// Note: This program can be easily modified to find the sum of digits of a number of any length.

#include<iostream>

using namespace std;

void main()

{
int input,b,c,d,e;

cout<<"\t\t******\"4 DIGITS PROGRAM\"******"<<endl;

cout<<endl<<endl<<endl;

cout<<"ENTER 4 DIGITS NUMBER\t";
cin>>input;

b=input%10;
input=input/10;
cout<<"THE DIGITS ARE\t";


c=input%10;
input=input/10;


d=input%10;
input=input/10;


e=input%10;
input=input/10;

cout<<e<<",";

cout<<d<<",";

cout<<c<<",";

cout<<b<<","<<endl<<endl<<endl;

cout<<"THE ADDITION OF THE DIGITS IS=\t";

cout<<b+c+d+e<<endl<<endl<<endl;
}

No comments:

Post a Comment