Write a Program C++ & Python to calculate the sum of two numbers

By | April 25, 2022

In this program, we will ask users to enter 2 numbers and print their sum as an output. Learn to calculate the sum of two numbers.

For example, if the user enters 2 numbers 3.2 and 4.5 the output should be 7.7

C++:

#include<iostream.h>
#include< conio.h>
#include<math.h>
void main()
{
clrscr();
float num_1,num_2,add;
cout<<"Enter the first number: ";
cin>>num_1;
cout<<"Enter the second number: ";
cin>>num_2;
cout<<"The sum of both the numbers is: "<<num_1+num_2;
getch();
}

Output:

Enter the first number: 4.7
Enter the second number: 3.4
The sum of both the numbers is: 8.1

Python:

num_1= float(input("Enter the first number: "))
nun_2= float(input("Enter the second number: "))
print("The sum of both the numbers is:",num_1+nun_2)

Output:

Enter the first number: 4.7
Enter the second number: 3.4
The sum of both the numbers is: 8.1

People are also reading:

Author: Vinay Singh

I am a Full Stack Developer with a Bachelor's Degree in Computer Science, who also loves to write technical articles that can help fellow developers.

Leave a Reply

Your email address will not be published.