C Program To Calculate Perimeter, Diagonal of a Square using its Side

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.

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

Formula To Calculate Area, Perimeter and Diagonal of a Square using its side

diagonal = sqrt(2) x side;

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

Perimeter = 4 x side;

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

diagonal of square using its side

Expected Output for the Input

User Input:
Enter length of side of the Square
10.5

Output:
Area of the Square is 110.250000
Perimeter of the Square is 42.000000
Diagonal of the Square is 14.849242

Video Tutorial: C Program To Calculate Perimeter, Diagonal of a Square using its Side


[youtube https://www.youtube.com/watch?v=QXO-lF-EbvA]

YouTube Link: https://www.youtube.com/watch?v=QXO-lF-EbvA [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Perimeter, Diagonal of a Square using its Side

#include < stdio.h >
#include < math.h >

int main()
{
    float perimeter, diagonal, side, area;

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

    perimeter = 4 * side;
    diagonal  = sqrt(2) * side;
    area      = side * side;

    printf("Area of the Square is %f\n", area);
    printf("Perimeter of the Square is %f\n", perimeter);
    printf("Diagonal of the Square is %f\n", diagonal);

    return 0;
}

Output 1:
Enter length of side of the Square
10
Area of the Square is 100.000000
Perimeter of the Square is 40.000000
Diagonal of the Square is 14.142136

Output 2:
Enter length of side of the Square
5
Area of the Square is 25.000000
Perimeter of the Square is 20.000000
Diagonal of the Square is 7.071068

Output 3:
Enter length of side of the Square
12.2
Area of the Square is 148.839996
Perimeter of the Square is 48.799999
Diagonal of the Square is 17.253405

Output 4:
Enter length of side of the Square
10.5
Area of the Square is 110.250000
Perimeter of the Square is 42.000000
Diagonal of the Square is 14.849242

Output 5:
Enter length of side of the Square
3.2
Area of the Square is 10.240001
Perimeter of the Square is 12.800000
Diagonal of the Square is 4.525484

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

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

C Program To Calculate Area of a Square using its Side

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

Formula To Calculate Area of Square using its side

area = side x side.

Note: All the sides of a square are equal.

Expected Output for the Input

User Input:
Enter the length of side of a square
5

Output:
Area of the Square is 25.00

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


[youtube https://www.youtube.com/watch?v=V-nCBIaMmYQ]

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

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

#include < stdio.h >

int main()
{
    float area, side;

    printf("Enter the length of side of a square\n");
    scanf("%f", &side);

    area = side * side;

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

    return 0;
}

Output 1:
Enter the length of side of a square
3
Area of the Square is 9.00

Output 2:
Enter the length of side of a square
4
Area of the Square is 16.00

Output 3:
Enter the length of side of a square
5
Area of the Square is 25.00

Output 4:
Enter the length of side of a square
6
Area of the Square is 36.00

Output 5:
Enter the length of side of a square
8
Area of the Square is 64.00

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