Q:

C++ program to add two integer numbers using function

0

C++ program to add two integer numbers using function

In the last program [<a href="https://nerdutella.com/q1120-C-plus-plus-program-to-add-two-integer-numbers" "="" style="box-sizing: border-box; color: rgb(0, 0, 255);" data-mce-href="https://nerdutella.com/q1120-C-plus-plus-program-to-add-two-integer-numbers">C++ program to add two integer numbers], we discussed how to take input and find the sum of two integer numbers?

In this program we are doing the same but using a user defined function, this program will take two integer numbers are calculate the sum/addition of them using a user defined function.

The function addition is used to calculate addition of the numbers, in this program we will pass the entered integer numbers and function will return the addition of the numbers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to add two numbers using function in C++

#include <iostream>
using namespace std;

//function declaration
int addition(int a,int b);

int main()
{
	int num1;	//to store first number
	int num2;	//to store second number
	int add;	//to store addition 
	
	//read numbers
	cout<<"Enter first number: ";
	cin>>num1;
	cout<<"Enter second number: ";
	cin>>num2;
	
	//call function
	add=addition(num1,num2);
	
	//print addition
	cout<<"Addition is: "<<add<<endl;
	
	return 0;
}

//function definition
int addition(int a,int b)
{
	return (a+b);
}

Output

Enter first number: 100 
Enter second number: 200
Addition is: 300

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Most popular and Searched C++ solved programs with Explanation and Output

Similar questions


need a help?


find thousands of online teachers now
C++ program to add two integer numbers using point... >>
<< C++ program to add two integer numbers...