-->

program to get area of circle using function named circle()

// program to get area of circle using function named circle()
#include<stdio.h>                      //header file
void circle();                              // function prototype/declaration with return type zero.
int main()                                  //main function
{
circle();                                     // function calling. you can call it as many as you want.
return 0;
}
void circle()                              // function body line ; also called function definition
{
 float radius;                            // variable declaration
float area;                                //variable declaration
printf("enter radius of circle\n");   // displays message to input data
scanf("%f",&radius);                   // gets data from user.
area=3.14*radius*radius;             // calculates result stores in area.
printf("the area is=%f\n",area);    // displays output
}
/* here we have used top down approach. i.e calling from top and writing its body line down.
 we can also reverse the process.*/

-----------------------------------------------------------------------------------------------------------------------
or
--------------------------------------------------------------------------------------------------

// program to get area of circle using function named circle(). we use here bottom up technique
#include<stdio.h>                      //header file
                                              // function prototype/declaration is not needed
void circle()                              // function body line/definition
{
 float radius;                            // variable declaration
float area;                                //variable declaration
printf("enter radius of circle\n");   // displays message to input data
scanf("%f",&radius);                   // gets data from user.
area=3.14*radius*radius;             // calculates result stores in area.
printf("the area is=%f\n",area);    // displays output
}
int main()                                  //main function
{
circle();                                     // function calling. you can call it as many as you want.
return 0;
}
// this (above method is now obsolete. if you want that you can use that. mostly we use top down.


No comments:

Post a Comment