In this program, we will learn about C program to calculate the area of square using function and without using the function.
For better understanding of the program, you should know about following C programming topic :
The formula to calculate the area of a square is:
Area = length * length
#include <stdio.h>
int main()
{
int square_side, area;
printf("Enter the side of square: ");
scanf("%d", &square_side);
//calculation of the area
area = square_side * square_side;
printf("Area of the square: %d", area);
return 0;
}
Output:
[adsense1]
/* program to calculate the area of square */
#include <stdio.h>
void area(); //function prototype
int main() //function main begins program execution
{
area(); //function call
return 0;
}
// end main
void area() //called function
{
int square_area, square_side;
printf("Enter the side of square:");
scanf("%d",&square_side);
square_area = square_side * square_side;
printf("Area of Square = %d",square_area);
} //end function area
Output: