
Additional program in C++: With programming, we can learn to solve various real-life problems easily. As a beginner, adding two numbers is the best starter. Let us learn to write additional programs using C++ language. The Additional program evaluates the sum of two or more numbers. We will also understand the concept based on analogy-based examples.
In this blog, you will learn the best way to add two variables using a C++ program code. Learning C++ language is very easy. Check the implementation below.
| Addition Program in C++ |
| #include <stdio.h> int main() { // Declare variables int n1, n2, sum; // Prompt the user to enter two integers printf("Enter two integers: "); // Read two integers from the user scanf("%d %d", &n1, &n2); // Calculate the sum of the two numbers sum = n1 + n2; // Print the result printf("%d + %d = %d\n", n1, n2, sum); return 0; } |
Also Check: What is DevOps? Simple Explanation
Description: Let us take a real-world example of an additional program in C++. Suppose you are a juice maker and you are making lemon juice for your customers.
You need to have two containers, one containing lemon extracted juice and other containing water. You need to add the two containers together to make the mixture. Suppose the two containers hold two variables. Now we need to add these two variables in a separate container and mix them together.| Addition Program in C++ |
| #include <iostream> using namespace std; int main() { double com1, com2, mix; count<< “Enter the quantity of component 1(ml): “; cin >> com1; cout<<” Enter the quantity of component 2 (ml): “ cin>>com2; mix = com1 + com2; cout<<” The mixture after addition forms: “ <<mix<<” ml<<endl; return 0; |
Output
| Enter the quantity of component 1 (ml): 5 Enter the quantity of component 2 (ml): 10 The mixture after addition forms 15 ml |