Submitted By: Name Muhammad Muheeb Javed Reg - No FA19-BCS-057 Section B Submitted To: MR - Usman Ali
Submitted By: Name Muhammad Muheeb Javed Reg - No FA19-BCS-057 Section B Submitted To: MR - Usman Ali
Submitted by:
Name Muhammad Muheeb Javed
Reg.no FA19-BCS-057
Section B
Submitted to: Mr.Usman Ali
A function is block of code that performs a specific task. C allows you to define
functions according to your need. These functions are known as user-defined
functions. For example: Suppose, you need to create a circle and color it depending
upon the radius and color.
1. #include <iostream>
2. using namespace std;
3.
4. // Function prototype (declaration)
5. int add(int, int);
6.
7. int main()
8. {
9. int num1, num2, sum;
10. cout<<"Enters two numbers to add: ";
11. cin >> num1 >> num2;
12.
13. // Function call
14. sum = add(num1, num2);
15. cout << "Sum = " << sum;
16. return 0;
17. }
18.
19. // Function definition
20. int add(int a, int b)
21. {
22. int add;
23. add = a + b;
24.
25. // Return statement
26. return add;
27. }