Adding and Subtracting Integers in C++


Welcome to C++ programming language. if you are new to C++, you have chosen a good platform to becoming a  better programmer.
today, we will show you how to use the C++ language to input two integers and compute the sum and difference between the two. 

Now ;This program uses the input stream object std::cin and the stream extraction
Operator, >>, to obtain two integers typed by a user at the keyboard, computes the sum and difference of these values and outputs the result using std::cout.


#include<iostream>

int main()
{
int number1;
int number2;
int sum; 
int difference; 

std::cout<< "Enter first integer:";
std::cin>>number1;

std::cout<<"Enter Second Integer:";
std::cin>>number2; 

sum = number1 + number2; 
difference = number1 - number2; 

std::cout<<"Sum is:"<<sum<<std::endl; 
std::cout<<"Difference is:"<<difference<<std::endl

}

Comments

Popular posts from this blog

Body Mass Index Calculator In C

Adding two Integers in Java Application

Calculating Product, sum, difference, and quotient of Five Integers