Showing posts with label Nesting of function. Show all posts
Showing posts with label Nesting of function. Show all posts

Friday 30 March 2012

Nesting of function


Nesting of function

#include<stdio.h>
#include<conio.h>

void main()
{
          Function1();
}

Function1()
{
Function2();
}

Function2()
{
         
}

As shown in the above example, Function1() is called from the main function. In the definition of the Function1(), Function2() is called. Thus, main function calls Function1, Function1 calls function2 and
Likewise it may continue. This type of function calls are known as nested function calls. We have previously studied nested for, nested if, similarly the same concept applies to the nested functions also.

Consider following example.

Example
#include<stdio.h>
#include<conio.h>

void getmarks();
void gettotal(int, int, int);
void getpercent(int);

void main()
{
clrscr();
getmarks();
getch();
}

 void getmarks()
{
int m1, m2,m3;
printf(“Enter the marks out of 100”);
scanf(“%d %d %d”,&ma,&m2,&m3);
gettotal(m1,m2,m3);
}

void gettotal(int m1,int m2,int m3)
{
int total;
total = m1+m2+m3;
printf(“\n The total marks : %d”,total);
getpercent(total);
}

void getpercent(int total)
{
float percent;
percent = (total/3);
printf(“\n The percentage is %.2f %”,percent);
}

Posted By :Ruchita Pandya