C program to find area of a parallelogram; Through this tutorial, we will learn how to find or calculate area of a parallelogram using standard formula, function and pointer in c programs.
Programs and Algorithm to Find Area of a Parallelogram
Let’s follow the following algorithm and program to find or calculate area of a parallelogram using standard formula, function and pointer in c:
- Algorithm to Find Area of a Parallelogram
- C Program to Find Area of a Parallelogram using Formula
- C Program to Find Area of a Parallelogram using Function
- C Program to Find Area of a Parallelogram using Pointer
Algorithm to Find Area of a Parallelogram
Use the following algorithm to write a program to find the area of a parallelogram; as follows:
- Take input base and height of parallelogram. Store it in two different variables.
- Calculate area of parallelogram using
perimeter=2*(length+breadth) - Finally, print the value of area of parallelogram.
C Program to Find Area of a Parallelogram using Formula
#include<stdio.h>
int main()
{
float base,height,area;
printf("enter base of parallelogram: ");
scanf("%f",&base);
printf("enter height of the parallelogram: ");
scanf("%f",&height);
area=(base*height);
printf("Area of parallelogram: %f\n",area);
return 0;
}
The output of the above c program; as follows:
enter base of parallelogram: 10 enter height of the parallelogram: 30 Area of parallelogram: 300.000000
C Program to Find Area of a Parallelogram using Function
#include<stdio.h>
float area(float b,float h)
{
return (b*h);
}
int main()
{
float b,h,a;
printf("enter base: ");
scanf("%f",&b);
printf("enter height: ");
scanf("%f",&h);
a=area(b,h);
printf("Area of parallelogram: %f\n",a);
return 0;
}
The output of the above c program; as follows:
enter base: 55 enter height: 63 Area of parallelogram: 3465.000000
C Program to Find Area of a Parallelogram using Pointer
#include<stdio.h>
void area(float *b,float *h,float *area)
{
*area=((*b)*(*h));
}
int main()
{
float b,h,a;
printf("enter base: ");
scanf("%f",&b);
printf("enter height: ");
scanf("%f",&h);
area(&b,&h,&a);
printf("Area of parallelogram: %f\n",a);
return 0;
}
The output of the above c program; as follows:
enter base: 5 enter height: 63 Area of parallelogram: 315.000000