In: Computer Science
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions:
a. to compute for the sum of two numbers (n1, n2) using
function.
CODE
#include <iostream>
using namespace std;
//Void Function
void dispName(){
//Display Name
cout<<"John\n";
//Void function do not return any value
}
//Return value of function Sum is Integer
int sum(int n1,int n2){
//return n1+n2
return(n1+n2);
}
int main()
{
//Calling
dispName();
// Taking input n1,n2
int n1,n2,result;
cout<<"Enter Number 1: ";
cin>>n1;
cout<<"Enter Number 2: ";
cin>>n2;
//Calling
result=sum(n1,n2);
//Print the result
cout<<"Result: "<<result;
return 0;
}
CODE SNIPPET
OUTPUT