0% found this document useful (1 vote)
212 views

Polygon Area Calculator in C Language

This C program uses nested switch statements to calculate the area of different polygon shapes based on user input. The user is prompted to select between a regular polygon, irregular polygon, or closed figure with zero sides. Depending on their selection, further inputs may be required to calculate the specific area formula. For example, if the user selects a triangle under the irregular polygon option, they will then provide the three side lengths to calculate the area using Heron's formula. The program handles various polygon types including circles, triangles, quadrilaterals, and ellipses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
212 views

Polygon Area Calculator in C Language

This C program uses nested switch statements to calculate the area of different polygon shapes based on user input. The user is prompted to select between a regular polygon, irregular polygon, or closed figure with zero sides. Depending on their selection, further inputs may be required to calculate the specific area formula. For example, if the user selects a triangle under the irregular polygon option, they will then provide the three side lengths to calculate the area using Heron's formula. The program handles various polygon types including circles, triangles, quadrilaterals, and ellipses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int ca;
do
{
printf("#################################################\n");
printf("## Press 1 For Regular Polygon. ##\n");
printf("## Press 2 For Irregular Polygon. ##\n");
printf("## Press 3 For Closed Figure with Zero Side. ##\n");
printf("## Press Other for Exit. ##\n");
printf("#################################################\n");
ca;
scanf("%d",&ca);
switch(ca)
{
case 1:
{
printf("Enter the number of sides : ");
int n;
scanf("%d",&n);
printf("\nEnter the length of one side : ");
int l;
scanf("%d",&l);
double p=n*l;
double k=3.14/n;
double tx=tan(k);
double a=l/(2*tx);
double area=(p*a)/2;
printf("%lf\n",area);
}//end of case 1
break;
case 2:
{
printf("In Irregular there are further classifications :-->\n ");
printf("\tPress 1 for 3 Sided Figures.\n");
printf("\tPress 2 for 4 Sided Figures.\n");
int cs;
scanf("%d",&cs);
if(cs==1)
{
printf("Enter the three sides of Triangle \n");
int ta,tb,tc;
scanf("%d\n%d\n%d\n",&ta,&tb,&tc);
double semip=(ta+tb+tc)/2;
double areatri=sqrt(semip*(semip-ta)*(semip-tb)*(semip-tc));
printf("Area Of Triangle = %lf\n",areatri);
}
else if(cs==2)
{
printf("Enter the length of all four side notation as a,b,c,d\n
");
double a1,b1,c1,d1;
scanf("%lf\n%lf\n%lf\n%lf\n",&a1,&b1,&c1,&d1);
printf("Enter the angle between a & d and b & c \n");
double angle1,angle2;
scanf("%lf\n%lf\n",&angle1,&angle2);
double sangle1=sin((3.14/180)*angle1);
printf("%lf",sangle1);
double sangle2=sin((3.14/180)*angle2);
printf("%lf",sangle2);
double area1=0.5*((a1*d1*sangle1)+(c1*b1*sangle2));
printf("Area = %lf\n",area1);
}
else
{
printf("Wrong Input");
}
}//end of case 2
break;
case 3 :
{
printf("\tPress 1 for Circle.\n");
printf("\tPress 2 for Eclipse.\n");
int cir;
scanf("%d",&cir);
switch(cir)
{
case 1:
{
printf("Enter The Radius of Circle:-->\n");
double rad;
scanf("%lf",&rad);
double areacir=3.14*rad*rad;
printf("Area = %lf\n",areacir);
}//end of sub case for circle
break;
case 2:
{
printf("Enter the major axis and minor axis of
eclipse\n");
double axis1,axis2;
scanf("%lf\n%lf",&axis1,&axis2);
double areaecl=axis1*axis2*3.14;
printf("Area = %lf\n",areaecl);
}//end of sub case for ellipse
break;
default: printf("circle wrong");
}//end of inner switch
}//end of case 3
default : printf(" ");
}//end of outer switch case
}while(ca==1||ca==2||ca==3);//end of do loop
getch();
}//end of main

You might also like