Tuesday 8 January 2013

Let Us C Chapter 1 Problem No:H-i


#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 for four digit number
int b,c,d,f;
b=a%10;a=a/10;c=a%10;a=a/10;d=a%10;a=a/10;f=a;
cout<<"This is the sum of last and first order: "<<(b+f)<<endl;
// by effienct way use any digit number
    b=0,d;
cout<<"\nThis is also the sum of first and last order: "<<endl<<endl;
b=aa%10;
do
{
d=aa%10;
aa/=10;
}while(aa>0);
cout<<"This is the sum of first and last order: "<<(b+d)<<endl<<endl;
}

No comments:

Post a Comment

Comments please: