C++ program to add two numbers

Write a program to add two numbers x and y. Store the result in a variable z.

#include<iostream>
using namespace std;
int main(){
	int x,y,z;
	cout<<"Enter two numbers "<<endl;
	cout<<"x : ";
	cin>>x;
	cout<<"y : ";
	cin>>y;
	z = x+y;
	cout<<"Sum of two numbers is "<<z<<endl;
	return 0;
}
Program shows the output of adding two numbers
Program shows the output of adding two numbers

Try the following

Program that inputs two value x and y. Subtract y from x and store in variable z. (z = x-y)

Program that inputs two value x and y. Divide x from y and store in variable z. (z = x/y)

Program that inputs two value x and y. Multiply x and y and store in variable z. (z = x*y)

Program that inputs two value x and y. Use operator % and store value in z. (z = x%y). It gives the remainder when x is divided by y and store it into z.

One Reply to “C++ program to add two numbers”

Leave a Reply

Your email address will not be published. Required fields are marked *