Ad Code

write a program in c++ to print the sum of two numbers using variables

Advertisements

write a program in c++ to print the sum of two numbers using variables

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b, sum;

cout<<"Please enter any two numbers"<<<<endl;

cin>>a>>b;

sum=a+b;

cout<<"Sum of <<a <<"and"<<b " is "<<sum;

getch();

}



Or


#include <iostream> using namespace std; int main() { cout << "\n\n Print the sum of two numbers :\n"; cout << "-----------------------------------\n"; int a; int b; int sum; a=29; b=30; sum=a+b; cout << " The sum of "<< a << " and "<<b <<" is : "<< sum <<"\n\n" ; }


Program to Add Two Integers

#include <iostream>
using namespace std;

int main() {

  int a, b, sum;
    
  cout << "Enter two integers: ";
  cin >> a>> b;
  sum = a + b;
  cout << first_number << " + " <<  second_number << " = " << sum;     
  return 0;
}

Output

Enter two integers: 4
5
4 + 5 = 9
Download Link
Advertisements

Post a Comment

0 Comments