C Program To Calculate Area of a Square using its Diagonal


Lets write a C program to find area of a square by using length of its diagonal. We ask the user to input the length of its diagonal.

Related Read:
C Program To Calculate Area of a Square using its Side

Formula To Calculate Area of Square using its diagonal

area = ( diagonal x diagonal ) / 2.0
OR
area = ( diagonal x diagonal ) * 0.5

Note: All the sides of a square are equal. Both the diagonals of the square are of equal length.

area of square using its diagonal

Expected Output for the Input

User Input:
Enter length of diagonal of a Square
15.2

Output:
Area of the Square is 115.52

Video Tutorial: C Program To Calculate Area of a Square using its Diagonal


[youtube https://www.youtube.com/watch?v=7TCCRv174iE]

YouTube Link: https://www.youtube.com/watch?v=7TCCRv174iE [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Area of a Square using its Diagonal

#include < stdio.h >

int main()
{
    float area, diagonal;

    printf("Enter length of diagonal of a Square\n");
    scanf("%f", &diagonal);

    area = (diagonal * diagonal) * 0.5;

    printf("Area of the Square is %0.2f\n", area);

    return 0;
}

Output 1:
Enter length of diagonal of a Square
9
Area of the Square is 40.50

Output 2:
Enter length of diagonal of a Square
5
Area of the Square is 12.50

Output 3:
Enter length of diagonal of a Square
10
Area of the Square is 50.00

Output 4:
Enter length of diagonal of a Square
10.5
Area of the Square is 55.13

Output 5:
Enter length of diagonal of a Square
12.2
Area of the Square is 74.42

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *