Write in C++ program and write a function named add. It should accept two const double type references as arguments. The first argument should be named num1; the second argument should be named num2. The function should return by value of num1 plus num2.
C++ code:
#include <iostream>
using namespace std;
//initializing add function
double add(const double &num1,const double &num2){
//returning num1+num2
return num1+num2;
}
int main()
{
//initializing a sample value for num1 and num2
double num1=1,num2=2;
//calling add function and printing the result
cout<<add(num1,num2)<<endl;
return 0;
}
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.