Nested Functions
If more than One
function is Called in a single line then the principle is
called as ‘Nested
Function’.
It is mostly useful
when a series of Arithmetical Transactions fall in a Single
Formula.
The Result of a
Particular Function need to be DEPENDENT on the
OPERATION carried out
by ANOTHER FUNCTION.
Illustrative Example
Program
#include
<stdio.h>
void main()
{
int add(int, int);
int sub(int, int);
int mult(int, int);
float div(int, int);
int a, b, c, d, f, g,
h, R;
a = 3; b = 2; c = 4;
d = 5; f = 8; g = 2; h = 6;
R = sub(mult(add(a,
b), add(c, d)), add(div(f, g), h));
printf("\nThe
Result of the Expression is : %d", R);
}
float div(int x, int
y)
{
return((float)x /
(float)y);
}
int mult(int x, int
y)
{
return(x * y);
}
int add(int x, int y)
{
return(x + y);
}
int sub(int x, int y)
{
return(x - y);
}
No comments:
Post a Comment