ADVERTISEMENT
ADVERTISEMENT

C program to calculate the area of Parallelogram

Here, we are going to learn how to calculate the area of Parallelogram using C program?
Submitted by Nidhi, on August 05, 2021

Problem Solution:

Read the values of base and altitude of Parallelogram from the user, and calculate the area of Parallelogram.

Area of Parallelogram formula = b x h

Where b is the base and h is the height or altitude of the Parallelogram.

Program:

The source code to calculate the area of the Parallelogram is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to calculate the area of Parallelogram

#include <stdio.h>

float calcuateAreaOfParallelogram(float base, float altitude)
{
    float result = 0.0F;

    result = base * altitude;

    return result;
}

int main()
{
    float base = 0;
    float altitude = 0;
    float area = 0;

    printf("Enter the value of base: ");
    scanf("%f", &base);

    printf("Enter the value of altitude: ");
    scanf("%f", &altitude);

    area = calcuateAreaOfParallelogram(base, altitude);

    printf("Area of Parallelogram is: %f\n", area);

    return 0;
}

Output:

RUN 1:
Enter the value of base: 1.2
Enter the value of altitude: 2.3
Area of Parallelogram is: 2.760000

RUN 2:
Enter the value of base: 12.34
Enter the value of altitude: 34.56
Area of Parallelogram is: 426.470428

RUN 3:
Enter the value of base: 1
Enter the value of altitude: 1.2
Area of Parallelogram is: 1.200000

Explanation:

In the above program, we created two functions calcuateAreaOfParallelogram() and main(). The calcuateAreaOfParallelogram() function is used to calculate the area of Parallelogram based on the given base and altitude.

In the main() function, we read the values of base and altitude of the Parallelogram from the user. Then we called the calcuateAreaOfParallelogram() function to calculate the area of the Parallelogram. After that, we printed the result on the console screen.

C Basic Programs »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.