For new coders out there here's a sample c program to compute Area of a Circular Sector and Arc length
Here's the code;
#include
#include
float ComputeSectArea();
float ComputeArcLength();
void main(void){
int choice;
float AreaSector,ArcLength;
clrscr();
printf("\nWhat would you like to do?");
printf("\n[1] Compute Area of Sector");
printf("\n[2] Compute Arc Length");
printf("\nEnter Choice: ");
scanf("%d",&choice);
if (choice == 1){
AreaSector = ComputeSectArea();
printf("\n Area of Sector is %.2f",AreaSector);
}
else {
ArcLength = ComputeArcLength();
printf("\n Arc Length is %.2f",ArcLength);
}
getch();
}
float ComputeSectArea(){
int theta;
int radius;
float area_of_sector,pi=3.14;
printf("\nPlease enter theta:\t");
scanf("%d",&theta);
fflush(stdin);
printf("\nPlease enter radius:\t");
scanf("%d",&radius);
fflush(stdin);
area_of_sector= ((float)theta / (float)360.00) * pi * radius * radius;
return area_of_sector;
}
float ComputeArcLength(){
int theta;
int radius;
float length_of_arc;
printf("\nPlease enter theta:\t");
scanf("%d",&theta);
fflush(stdin);
printf("\nPlease enter radius:\t");
scanf("%d",&radius);
fflush(stdin);
length_of_arc= ((float)theta / (float)180.00) * radius;
return length_of_arc;
}
C Program to Compute Area of Sector and Arc Length
Posted by nika perales | 9:37 AM | C Programming | 0 comments »
Subscribe to:
Post Comments (Atom)
0 comments
Post a Comment