C program to find area of rhombus; Through this tutorial, we will learn how to find or calculate area of rhombus using standard formula, function and pointer in c programs.
Programs and Algorithm to Find Area of Rhombus
Let’s checkout the following algorithm and programs to find or calculate area of rhombus using standard formula, function and pointer in c:
- Algorithm to Find Area of Rhombus
- C Program to Find Area of Rhombus using Standard Formula
- C Program to Find Area of Rhombus using Function
- C Program to Find Area of Rhombus using Pointer
Algorithm to Find Area of Rhombus
Use the following algorithm to write a program to find the area of the rhombus; as follows:
- Take input two side of area of rhombus. Store it in two different variables.
- Calculate area of rhombus using
area=(d1*d2)/2; - Finally, print the value of Area of rhombus.
C Program to Find Area of Rhombus using Standard Formula
#include<stdio.h>
int main()
{
float d1,d2,area;
printf("enter diagonal1 of rhombus: ");
scanf("%f",&d1);
printf("enter diagonal1 of rhombus: ");
scanf("%f",&d2);
area=(d1*d2)/2;
printf("Area of Rhombus: %f\n",area);
return 0;
}
The output of the above c program; as follows:
enter diagonal1 of rhombus: 5 enter diagonal1 of rhombus: 6 Area of Rhombus: 15.000000
C Program to Find Area of Rhombus using Function
#include<stdio.h>
float area(float d1,float d2)
{
return (d1*d2)/2;
}
int main()
{
float d1,d2,a;
printf("enter diagonal1 of rhombus: ");
scanf("%f",&d1);
printf("enter diagonal2 of rhombus: ");
scanf("%f",&d2);
a=area(d1,d2);
printf("Area of Rhombus: %f\n",a);
return 0;
}
The output of the above c program; as follows:
enter diagonal1 of rhombus: 10 enter diagonal2 of rhombus: 20 Area of Rhombus: 100.000000
C Program to Find Area of Rhombus using Pointer
#include<stdio.h>
void area(float *d1,float *d2,float *area)
{
*area=((*d1)*(*d2))/2;
}
int main()
{
float d1,d2,a;
printf("enter diagonal1 of rhombus: ");
scanf("%f",&d1);
printf("enter diagonal2 of rhombus: ");
scanf("%f",&d2);
area(&d1,&d2,&a);
printf("Area of Rhombus: %f\n",a);
return 0;
}
The output of the above c program; as follows:
enter diagonal1 of rhombus: 6 enter diagonal2 of rhombus: 7 Area of Rhombus: 21.000000