Lets write a C program to calculate area, perimeter and diagonal of a square by using length of its side. We ask the user to input the length of its side.
Formula To Calculate Area, Perimeter and Diagonal of a Square using its side
diagonal = sqrt(2) x side;
area = ( diagonal x diagonal ) / 2.0
area = ( diagonal x diagonal ) * 0.5
area = side x side;
Perimeter = 4 x side;
Expected Output for the Input
Enter length of side of the Square
Area of the Square is 110.250000
Perimeter of the Square is 42.000000
Diagonal of the Square is 14.849242
Note: All the sides of a square are equal. Both the diagonals of the square are of equal length.
C Programming Interview / Viva Q&A List
C Programming: Beginner To Advance To Expert