Tuesday 24 December 2013

(i) If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number(c++ code)


#include<iostream>
using namespace std;
#include<conio.h>
int main ()
{
float a,d,t;
int a1,d1,t1,u;
cout<<"\nInput a 4 digit number";
cin>>t;
a=t/1000.0;
u=t;
a1=a;
d=u%10;
d1=d;
t1=a1+d1;
cout<<"\nThe Sum of 1st ["<<a1<<"] digit and last ["<<d1<<"] digit is = "<<t1;
getch();
 return 0;

  /*  Letuswithc:

       this page is designed to help you learn C or C++.
  Understandable C and C++ programming tutorials, compiler reviews, source code, tips and tricks. 
         */
        
         }

No comments:

Post a Comment