Question
My C code below doesn't run. Please, fix it. /* * This C program works with triangles. */ #define _CRT_SECURE_NO_WARNINGS #include #include void Pascal(int rows)
My C code below doesn't run. Please, fix it.
/*
* This C program works with triangles.
*/
#define _CRT_SECURE_NO_WARNINGS
#include
#include
void Pascal(int rows) { //defination for pascal function
int coef = 1, space, i, j;//varaiables used to this funciton
for (i = 0; i < rows; i++) { // loop runs until number of rows
for (space = 1; space <= rows - i; space++) //for printing the spaces
printf("");
for (j = 0; j <= i; j++) { //loop runs with i number
if (j == 0 || i == 0) //intially coef is 1
coef = 1;
else
coef = coef * (i - j + 1) / j;// else claculating the pascal numbers
printf("%4d", coef);//printing the pascal number
}
printf(" ");//printing newline for next line
}
}
double Heron(double a, double b, double c) { //heron funciton defination
double p = (a + b + c) / 2; //calculating the p
double area = sqrt(p * (p - a)(p - b)(p - c));//claculating the area using herons formula
return area;//returning the area
}
double areaHeight(double* area, double* height) {//area_height funciton
double side1, side2, angle, radian;//to store the sides and angle
printf("Enter side1 side2: ");//taking sides form user
scanf("%lf %lf", &side1, &side2);
printf("Enter Angle:");//taking angle from user
scanf("%lf", &angle);
// in math libaray sin function is used for radains so we converting the angle to radian
radian = angle / 57.2958;
//finding the area using the given function
*area = 0.5 * side1 * side2 * sin(radian);
//for finding the height we need know which is hypotenus and which is another side.
//maximum value of side is hypotenus so for that we use terinary operator for this
double hyp = (side1 > side2) ? side1 : side2;
//minimum value of side is adjacent side so for that we use terinary operator
double side = (side1 < side2) ? side1 : side2;
//calculating the height with pythogrean theorem
*height = sqrt(hyp * hyp - side * side);
}
int main(void) { //main funciton
int choice; //taking for choice
while (1) {
//this for printing the menu
printf("*Menu** ");
printf("1.Pascal ");
printf("2.Heron ");
printf("3.Area/Height ");
printf("4.Quit ");
printf(" ");
//taking choice from user
printf("Enter the Choice: ");
scanf("%d", &choice);
printf(" ");
if (choice == 1) { //if the choice is 1
int rows; // to store the number of rows
printf("Enter the number of rows: ");
scanf("%d", &rows);//taking rows from user
Pascal(rows); //calling the pascal function with rows
printf(" ");
}
if (choice == 2) { //if choice is 2
double a, b, c, heron_area; //to store the side and area
printf("Enter the sides a b c: ");
scanf("%lf %lf %lf", &a, &b, &c);//taking sides from user
heron_area = Heron(a, b, c);//calling the heron funciton that returns area
printf("Area is %0.2lf ", heron_area);//printing the area
printf(" ");
}
if (choice == 3) { //if choice is 3
double height, area;
areaHeight(&area, &height);//calling teh area height function
printf("Area is %0.2lf ", area); //printing the area
printf("Height is %0.2lf ", height);//printing the height
printf(" ");
}
if (choice == 4) {//if choice is 4 the quit
printf("Thank you for Using this calculator,Bye :-)");
printf(" ");
break;//break the loop
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started