How to Write a Program to Add Two Integer Numbers in C++

In our previous programs, we already have explained the main function and namespace std; Make sure you don’t forget to check those articles as well before you write your program;

This is the C++ Program to Add Two Integer Numbers in C++

Requirement is

  • Define Integer ‘a,b,c’;
  • And Add them and display output on C variable;

Program to Add Two Integer Numbers in C++

/* 
* File: main.cpp
* Author: Satya J
*
* Created on December 13, 2018, 2:28 PM
*/

#include <cstdlib>
#include <iostream>

using namespace std;

/*
* 
*/
int main(){

int a,b,c;

cout<<"Enter First Number:"<<endl;
cin>>a;
cout<<"Enter Second Number:"<<endl;
cin>>b;

c= a+b;

cout<<"The Sum is:" <<c;

return 0;
}

This is the very basic program, and it will only calculate two integers; Learn this and you will understand to write a program to calculate 3 numbers or more in integer form;

Output

Enter First Number:
10
Enter Second Number:
20
The Sum is:30
RUN SUCCESSFUL (total time: 6s)

Just be sure to stay tuned with us and let us know if you find any difficulties understanding these programs; Our next program for calculating 2 float numbers;

Share

Crazy Coder

Writing Codes for Good <3

You may also like...

Leave a Reply

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