A program to calculate the area of the room using structures in C.

·

1 min read

In this following program, we will take the length and breadth and calculate the area using structures in the c language.

The structure is a user-defined datatype in C language which allows us to combine data of different types together. Structure helps to construct a complex data type that is more practical. It is similar to an Array, but an array holds data of a similar type only. But the structure, on the other hand, can store data of any type.

Program :

// A program to calculate the area of the room using structures in C

#include <stdio.h>


    struct room                           //name of the structure is room
    {
        float length;
        float breadth;
        float area;
    };
    int main()
{

    struct room x;                                         
    printf("Enter length and breadth: ");
    scanf("%f%f",&x.length,&x.breadth);

    x.area = x.length * x.breadth;

    printf("%f",x.area);

}

console:

Enter length and breadth: 2
2
4.000000