Programming Fundamentals: Functions
Programming Fundamentals: Functions
Lecture 7
Functions
Programming Toolkit
Decisions
Loops
Sequences
C Language
void main ( )
{
….
}
Definition of Function
Or
int x ;
x = square ( i ) ;
Cout<<x;
Cube Program
int Cube(int number)
{
int result =1;
int count;
for (count=1; count<=number; count++)
{
result = result * number;
}
return result;
}
main()
{
int number;
cout<<"Enter any Number for calculating Cube : ";
cin>>number;
cout<<"You Entered Number is : "<<number<<"Cube is : "<<Cube(number)<<endl;
system("PAUSE");
}
Example: Function to calculate integer
power ( Xn )
#include <iostream>
system("PAUSE");
}
Calling function
Called function
Area of the Ring