

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to Add Two Numbers
Addition is a basic arithmetic operation. The program to add two numbers performs addition of two numbers and prints their sum on screen.
A program that demonstrates addition of two numbers is given as follows −
Example
#include <iostream> using namespace std; int main() { int num1=15 ,num2=10, sum; sum = num1 + num2; cout<<"Sum of "<<num1<<" and "<<num2<<" is "<<sum; return 0; }
Output
Sum of 15 and 10 is 25
In the above program the sum of two numbers i.e. 15 and 10 is stored in variable sum.
sum = num1 + num2;
After that it is displayed on screen using the cout object.
cout<<"Sum of "<<num1<<" and "<<num2<<" is "<<sum;
A program that uses an array to store two numbers and their sum as well is given as follows −
Example
#include <iostream> using namespace std; int main() { int a[3]; a[0]=7; a[1]=5; a[2]=a[0] + a[1]; cout<<"Sum of "<<a[0]<<" and "<<a[1]<<" is "<<a[2]; return 0; }
Output
Sum of 7 and 5 is 12
In the above program, the numbers to be added are stored in the 0 and 1 index of the array.
a[0]=7; a[1]=5;
After that, the sum is stored in the 2 index of the array.
a[2]=a[0] + a[1];
The sum is displayed on screen using the cout object.
cout<<"Sum of "<<a[0]<<" and "<<a[1]<<" is "<<a[2];
- Related Questions & Answers
- Java Program to Add Two Numbers
- Python program to add two numbers
- Java Program to Add the two Numbers
- Java Program to Add Two Complex numbers
- 8051 Program to Add two 8 Bit numbers
- 8085 Program to Add two 8 Bit numbers
- 8085 program to add two 16 bit numbers
- Program to Add Two Complex Numbers in C
- 8085 Program to Add two multi-byte BCD numbers
- 8086 program to add two 8 bit BCD numbers
- Add two numbers represented by two arrays in C Program
- Program to Add two multi-byte numbers in 8085 Microprocessor
- Program to Add two 8 Bit numbers in 8085 Microprocessor
- Program to add two numbers represented as strings in Python
- Write a program to add two complex numbers using C
Advertisements