139k views
2 votes
Write a programe to add two numbers using function with return type"void".

1 Answer

4 votes

Answer:

#include<iostream>

using namespace std;

//create the function which add two number

void addTwoNumber(int num_1,int num_2)

{

int result = num_1 + num_2; //adding

cout<<"The output is:"<<result<<endl; //display on the screen

}

//main function

int main(){

//calling the function

addTwoNumber(3,6);

return 0;

}

Step-by-step explanation:

First, include the library iostream for using the input/output instructions.

then, create the function which adds two numbers. Its return type is void, it means the function return nothing and the function takes two integer parameters.

then, use the addition operation '+' in the programming to add the numbers and store the result in the variable and display the result.

create the main function for testing the function.

call the function with two arguments 3 and 6.

then, the program copies the argument value into the define function parameters and then the program start executing the function.

User Tkokasih
by
4.8k points