- On
- By
- 0 Comment
- Categories: addition, Calculations
Cpp program to sum two numbers
Cpp program to sum two numbers
In this tutorial, we will discuss the topic of Cpp program to sum two numbers
In this topic, we will learn how to add two numbers in C++ programming language
Find Sum to numbers Example- 1
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int f_no=45, s_no=35,sum;//variable declaration sum=f_no+s_no; //find sum of integers cout << "sum of two numbers: "<<sum<< endl;//display result getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Sum of two numbers: 80
Find Sum to numbers(Get input from user) – Example- 2
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int f_no, s_no,sum; cout << "Enter the first number: "<< endl; cin>>f_no;//get input from user for f_no cout << "Enter the second number: "<< endl; cin>>s_no; //get input from user for s_no sum=f_no+s_no; //find sum of numbers cout << "sum of two numbers: "<< endl; cout <<f_no<<" + "<<s_no<<" = "<<sum<< endl; //display the result getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter the first number: 75 Enter the second number: 65 sum of two numbers 75 + 65 = 140
In this program, the user has entered two integer values. These two values are stored in variables f_no, s_no.
Then both of values are added using plus (+) operator and stored in sum variable.
Finally, the sum is displayed on the screen
Similar post
C++ program to multiply two numbers using function
Java program to multiply two numbers using method
Python program to multiply two numbers using function
C# program to multiply two numbers using function
PHP program to multiply two numbers using function
C program to multiply two numbers
C++ program to multiply two numbers
Java program to multiply two numbers
Python program to multiply two numbers
C# program to multiply two numbers
PHP program to multiply two numbers
JavaScript program to multiply two numbers
Calculate the total of array elements in Java
Calculate the total of array elements in C
Calculate the total of array elements in C++
Java program to calculate sum of array elements
C program to calculate sum of array elements
Java Program to calculate average of array
C Program to calculate average of array
Java Program to calculate average of odd and even numbers in an array
Java Program to calculate average of odd and even numbers
C Program to calculate average of odd and even numbers in an array
C Program to calculate average of odd and even numbers
C++ Program to calculate average of odd and even numbers in an array
C++ Program to calculate average of odd and even numbers
Data types and variable in Java
Find product of two numbers using recursion in Java