-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14functions.cpp
More file actions
33 lines (31 loc) · 1.15 KB
/
Copy path14functions.cpp
File metadata and controls
33 lines (31 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;
int sum(int a, int b) // this is a function that takes arguments and performs a task which can be called elsewhere as many times as you want
{
return a + b;
}
// a function can't be written after the main function as it will throw error, to do that mention the prototype of the function before the main
// PROTOTYPE FUNCTION
int division(int, int); // no variables is also a valid option
void greet() //this is a void function which requires no return values
{
cout<<"Hello and good morning user"<<endl;
}
int main()
{
int num1, num2; //num1 and num2 are actual parameters that have the value and give it to formal parameters
cout << "Enter num1" << endl;
cin >> num1;
cout << "Enter num2" << endl;
cin >> num2;
cout << "The sum of num1 and num2 is " << sum(num1, num2) << endl;
cout << "The division of num1 and num2 is " << division(num1, num2) << endl;
greet();
return 0;
}
int division(int a, int b)
{
//here a and b are formal parameters that take value from actual parameters
return a / b;
}
//formal parameters and actual parameters can have the same name or different names