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
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
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
Suggested for you
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…