Skip to content

Commit f972aa2

Browse files
added tutorial 15 cpp file from local machine
1 parent 1106809 commit f972aa2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tut15.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
// Function prototype
5+
// syntax ---> function-name (arguments);
6+
// gives assurity that required function is present int the code
7+
8+
// int sum(int a, int b); // -- Acceptable
9+
// int sum(int a, b); // -- Not Acceptable
10+
int sum(int, int); // -- Acceptable
11+
12+
// void g(void); acceptable//
13+
void g ();
14+
15+
int main () {
16+
int num1, num2;
17+
18+
printf("Enter first number: ");
19+
scanf("%d", &num1);
20+
21+
printf("\n");
22+
23+
printf("Enter second number: ");
24+
scanf("%d", &num2);
25+
26+
printf("\n");
27+
28+
// num1, num2 are actual parameters
29+
printf("The sum is: ");
30+
printf("%d", sum(num1, num2));
31+
32+
g();
33+
34+
return 0;
35+
}
36+
37+
// defining a function
38+
int sum(int a, int b) {
39+
// Formal Paramertes, a and b will be taking values
40+
// from actual parameters num1 and num2
41+
int c = a+b;
42+
return c;
43+
}
44+
45+
// void functions
46+
void g() {
47+
printf("This is a greeting messge!");
48+
}

0 commit comments

Comments
 (0)