Page 82 - Modular_V1.1_Flipbook
P. 82
int num;
clrscr();
cout<<”Enter a number: “;
cin>>num;
int a;
a = add(num);
cout << a;
getch();
}
int add(int j){
if(j >= 10)
j = j * j;
else
j = j * 2;
return (j);
}
Program 6: To print the tables from 1 to 10.
#include <iostream.h>
#include <conio.h>
void table();
void main(){
clrscr();
table();
getch();
}
void table(){
int i, j;
for(i=1;i<=10;++i){
for(j=1;j<=10;j++)
cout<<”\n”<<i<<” * “<<j<<” = “<<i*j;
}
}
Recap
A function is a block of organized and reusable code used to perform a particular task.
Built-in functions are predefined functions provided by C++.
C++ allows you to create your own functions which are known as user-defined functions.
The parameters passed at the time of declaring a function are called formal parameters.
There are two methods to call a function: call by value and call by reference.
The scope of a variable means how different parts of the program can access that variable.
80 Touchpad MODULAR (Version 1.1)-X

