how to define function prototypes in c 2b 2b

Solutions on MaxInterview for how to define function prototypes in c 2b 2b by the best coders in the world

showing results for - "how to define function prototypes in c 2b 2b"
Samuel
23 Jan 2021
1/* C++ Function Prototype and C++ Function Definition */
2
3#include<iostream.h>
4#include<conio.h>
5#include<stdlib.h>
6
7int add(int, int);         // function prototype
8int subtract(int, int);    // function prototype
9int multiply(int, int);    // function prototype
10int divide(int, int);      // function prototype
11
12void main()
13{
14	clrscr();
15	int a, b;
16	cout<<"Enter any two number: ";
17	cin>>a>>b;
18	cout<<"\nSummation = "<<add(a, b);
19	cout<<"\nSubtraction = "<<subtract(a, b);  
20	cout<<"\nMultiplication = "<<multiply(a, b); 
21	cout<<"\nDivision = "<<divide(a, b); 
22	getch();
23}
24
25int add(int x, int y)     // function definition
26{
27	int res;
28	res = x + y;
29	return res;
30}
31
32int subtract(int x, int y)    // function definition
33{
34	int res;
35	res = x - y;
36	return res;
37}
38
39int multiply(int x, int y)    // function definition
40{
41	int res;
42	res = x * y;
43	return res;
44}
45
46int divide(int x, int y)    // function definition
47{
48	if(y==0)
49	{
50		cout<<"\n\nDivide by Zero Error..!!";
51		cout<<"\nPress any key to exit...";
52		getch();
53		exit(1);
54	}
55	else
56	{
57		int res;
58		res = x / y;
59		return res;
60	}
61}