C++ Program to Add Two Numbers2 min read

In this tutorial, we will write a C++ program for the addition of two numbers. We can add the integers, floats, double, etc using the same program just changing the type.

The program takes the user inputs for the number to be added then displays the result. We will see to add two numbers in three different ways in C++

  • Add two numbers in main function
  • Add two numbers using function
  • Add Two Numbers in using Class

C++ Program to Add Two Numbers

Output:

Enter First Numbers: 5
Enter Second Numbers: 3

Addition Result: 8

You can change the data type as required and use the same code.


Add two numbers using Function in C++

The program takes the user input the same as above, the only difference is the function is created for the calculation and return the result.

Output:

Enter First Numbers: 20
Enter Second Numbers: 5

Addition Result: 25


Add Two Numbers in C++ using Class

Here separate class is created to get the values and add the numbers and return to the main function.

Output:

Enter First Numbers: 10
Enter Second Numbers: 6

Addition result: 16


MORE

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …
Read More

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More