Tuesday 8 January 2013

Let Us C Chapter 1 Problem No:H-g


#include<iostream.h>
#include<conio.h>
void main()
{
int a,aa; // inputs the number
cin>>a;aa=a; // save the value for other code
// we do this as simple way first way
int b,c,d,e,f;
b=a%10;a=a/10;c=a%10;a=a/10;d=a%10;a=a/10;e=a%10;a=a/10;f=a;
cout<<"This is the sum of the digits: "<<(b+c+d+e+f)<<endl;
// by effienct way use any digit number
    int sum=0;b=0;
do
{
b=aa%10;
sum=sum+b;
aa/=10;
}while(aa>0);
cout<<"This is the sum of the digits: "<<sum<<endl;
}

No comments:

Post a Comment

Comments please: