The three digit number and find the sum of the first and the last digit in C++
e.g.
num = 345
sum = 3+5=8
#include<iostream.h>
#include<conio.h>
void main()
{
int num,sum;
clrscr();
//read the three digit number
cout<<endl<<"Enter the three digit number :";
cin>>num ;
//extract the first and the last digit
int a,b;
a=num/100;
b=num%10;
sum =a+b;
cout<<endl<<"Sum of digits = " <<sum;
getch();
}
void main()
{
int num,sum;
clrscr();
//read the three digit number
cout<<endl<<"Enter the three digit number :";
cin>>num ;
//extract the first and the last digit
int a,b;
a=num/100;
b=num%10;
sum =a+b;
cout<<endl<<"Sum of digits = " <<sum;
getch();
}
Comments
Post a Comment