Problem In Hand
C Program to calculate and print area and perimeter of square
Process and Solution Of Problem
Take input for side of square and store in a variable
calculate and store area of square in variable.
calculate and store perimeter of square in another variable.
further display area and perimeter
Program/Source Code
#include <stdio.h>
int main()
{
int s,a,p;
printf("Enter side of square ");
scanf("%d",&s);
a=s*s;
p=4*s;
printf("Area = %d perimeter = %d",a,p);
return 0;
}
Program Explanation
On execution of the program
* user enteres the side of square and store in a variable “s”
* Calculation is performed and area is stored in a variable “a” i.e. a=s*s;
* Calculation is performed and perimeter is stored in variable “p” i.e. p=4*s;
* then the result area and perimeter is displayed on the screen
Output:
Enter side of square 5 Area = 25 perimeter = 20
You May Also Like:
C Program to find largest of 3 numbers
C Program to print table of a number
C program to check number is +ve, -ve or zero
C program to check number is prime number or not
C program to convert total inches to feet and inches.
| <<< Previous: Sum , Product and Difference of two numbers | Area and Perimeter of rectangle : Next >>> |
Tutorials | Technical Questions | Interview Questions |
|---|---|---|
|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions |




