Page 89 - Modular_V2.0_C++_Flikpbook
P. 89
For example:
void main()
{
display(21);
}
In the above code, we have provided the value for the age parameter in the display( ) function.
Let us merge all the codes to create a running program.
#include<iostream.h>
#include<conio.h>
DOSBox 0.74, Cpu speed: max 100%
int display(int age);
Your age is 21 years old.
void main()
{
clrscr();
display(21);
getch();
}
int display(int age)
{
cout<< "Your age is " << age << " years old.";
return 0;
}
Program 1: To calculate the addition, subtraction, multiplication, division and modulus of two
numbers using functions.
#include<iostream.h>
#include<conio.h>
int sum(int, int);
int sub(int, int); DOSBox 0.74, Cpu speed: max 100% cycles, Frames 0, Program:
int multi(int, int); Enter first number: 8
int div(int, int); Enter second number: 6
The sum of two numbers is: 14
int mod(int, int);
The difference of two numbers is: 2
void main() The product of two numbers is: 48
The division of two numbers is: 1
{
The remainder after dividing two numbers is: 2
int n1, n2;
_
clrscr();
cout<<"Enter first number: ";
cin>>n1;
cout<<"Enter second number: ";
cin>>n2;
87
Functions in C++

