


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























2
main() square ()
x y 2
argument (^) parameter
2
Area of the Ring
Outer Circle
Inner Circle
Area of Outer Circle ____^ Area of Inner Circle = Area of the Ring
Area of the Circle = pi * radius of the circle
void main ( )
{
double radius, ringArea;
ringArea = ( 3.1415926 * rad1 * rad1 ) โ ( 3.1415926 * rad2 * rad2 ) ;
Calculating ringArea without using Function
double circleArea ( double ); // Function Declaration
void main() { int rad1,rad2; rad1=20; rad2=32; ringArea = circleArea(rad1) โ circleArea (rad2); // Function Call }
double circleArea ( double radius ) // Function Definition { return ( 3.1415926 * radius * radius ) ; }
Calculating ringArea by using a Function
#include < stdio.h >
double raiseToPow ( double, int); // function prototype
void main ( ) { double x ; int i ; printf( โ Please enter the number โ ); scanf (โ%dโ, &x ) ; printf( " Please enter the integer power that you want this number raised to " ); scanf (โ%dโ, &i ) ; printf(โ%d raise to power %d is equal to %dโ, x, i , raiseToPow ( x , i ) ) ; //function call }
*double raiseToPow ( double x , int power ) // function definition { double result ; int i ; result = 1.0 ; for ( i = 1 ; i <= power ; i ++ ) { result * = x ; // result = result x } return ( result ) ; }
Program to implement x^n
Example: Call by Value
#include <stdio.h>
int func ( int ) ;
main ( )
{
int i = 10 ; printf( โIn main i = %dโ, i) ; func ( i ) ; printf( " Back in main, i = %d" , i) ;
}
Example: Call by Value
int func ( int i )
{
printf("In function f , i = %dโ, i) ; i *= 2 ; printf("In function f , i is now = %dโ , i) ; return i ;
}
Call by Reference
variable is changed
have to pass memory address of variable
2
main() square ()
x
y
argument (^) parameter
Identifiers
Scope of Identifiers
1.Local Scope
2.File Scope
void functionName ( )
{
{ int i ; }
โฆ..
}
Example: Block Scope
for ( int i = 0 ; i < 10 ; i++ ) {
}