FUNCTIONS IN C

Shra Wan
0



Functions:

Functions are the self-contained program that contains several block of
statement which performs the defined task. In C language, we can create one or more



Functions according to the requirements.


Usually, In C programs flows from top left to right bottom of main() functions. We can

create any number of functions below that main() functions. These function are call from main() function.
Requirement while creating a functions.

  •  Declare a function
  •  Call statement
  •  Definition of function.
After the function is called from the main(), the flow of control will return to the main()
function.

WAP to calculate simple interest using function

#include
float interest(void); //function declaration
int main()
{ float si;
si=interest(); //function call
printf("Simple interst is %.2f\n",si);
return 0;
}

float interest() //function definition
{
float p,t,r,i;
printf("Enter Principal, Time and Rate");
scanf("%f%f%f",&p,&t,&r);
i=(p*t*r)/100;
return i; //function return value
}

Post a Comment

0Comments

Thank you very much for your comment.

Post a Comment (0)