C Programming Tutorial

Advertisements

Write a program to display sum of two numbers in C++



       #include<iostream.h>
       #include<conio.h>
       void main()
       {
              int n1,n2,sum;
              clrscr();
              clrscr();
              
              cout<<"\nEnter 1st number : "; 
              cin>>n1;

              cout<<"\nEnter 2nd number : "; 
              cin>>n2;
              
              sum = n1 + n2;
              
              cout<<"\nThe sum of "<<n1<<" and "<<n2<<" is "<<sum;

              getch();
       }
       
   Output : 

              Enter 1st number : 78
              Enter 2nd number : 45
              The sum of 78 and 45 is 123




Advertisement