I am writing a program that calculates the are of a triangle using the following formula: Area = (a2/2) * [sin α1 * sin αmgle2)/sin(αngle1 + αngle2). I am having issues with the angles because the angles need to always be greater than 0 and the sum of the 2 angles need to always be less than 180. Also, the area can't be a negative number. I almost got it down, but of course with an if statement nothing will print in the terminal if the conditions aren't meet. I've tried with a while loop, but was unsuccessful with that. What can I do so that this condition if(my_rank != 0 && alpha1 >= 1 && alpha2 >= 1 && alpha1 + alpha2 < 180) is always met? int a; int b; float c; bool m = false; alpha1 = rand()%180; alpha2 = rand()%180; baseA= (((float)rand()/(float)(RAND_MAX)) * 11 + 10) + ((float)rand()/(float)(RAND_MAX)); if(my_rank != 0 && alpha1 >= 1 && alpha2 >= 1 && alpha1 + alpha2 < 180){ m = true; MPI_Send(&alpha1, 1, MPI_FLOAT, 0, 0, MPI_COMM_WORLD); MPI_Send(&alpha2, 1, MPI_INT, 0, 0, MPI_COMM_WORLD); MPI_Send(&baseA, 1, MPI_INT, 0, 0, MPI_COMM_WORLD); printf("a = %.2f, alpha1 = %d, alpha2 = %d \n", baseA, alpha1, alpha2); }else{ a = alpha1; b = alpha2; c = baseA; area = areaTri(baseA, alpha1, alpha2); for(i = 1; i < comm_sz; i++){ MPI_Recv(&alpha1, 1, MPI_FLOAT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(&alpha2, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(&baseA, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); area = areaTri(baseA, alpha1, alpha2); my_rank = my_rank + i; } printf("a = %.2f, alpha1 = %d, alpha2 = %d \n", c, a, b); printf("Area of %d triangles is %.2f\n", my_rank, area); } MPI_Finalize(); return 0; } float areaTri (int base, float alpha1, float alpha2){ float area = pow(base, 2) * (sin(alpha1) * sin(alpha2)/sin(alpha1 +alpha2)); return area; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I am writing a program that calculates the are of a triangle using the following formula: Area = (a2/2) * [sin α1 * sin αmgle2)/sin(αngle1 + αngle2).

I am having issues with the angles because the angles need to always be greater than 0 and the sum of the 2 angles need to always be less than 180. Also, the area can't be a negative number. I almost got it down, but of course with an if statement nothing will print in the terminal if the conditions aren't meet. I've tried with a while loop, but was unsuccessful with that. What can I do so that this condition if(my_rank != 0 && alpha1 >= 1 && alpha2 >= 1 && alpha1 + alpha2 < 180) is always met?

int a;
int b;
float c;
bool m = false;
alpha1 = rand()%180;
alpha2 = rand()%180;
baseA= (((float)rand()/(float)(RAND_MAX)) * 11 + 10) + ((float)rand()/(float)(RAND_MAX));

if(my_rank != 0 && alpha1 >= 1 && alpha2 >= 1 && alpha1 + alpha2 < 180){
m = true;
MPI_Send(&alpha1, 1, MPI_FLOAT, 0, 0, MPI_COMM_WORLD);
MPI_Send(&alpha2, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
MPI_Send(&baseA, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
printf("a = %.2f, alpha1 = %d, alpha2 = %d \n", baseA, alpha1, alpha2);


}else{
a = alpha1;
b = alpha2;
c = baseA;
area = areaTri(baseA, alpha1, alpha2);
for(i = 1; i < comm_sz; i++){
MPI_Recv(&alpha1, 1, MPI_FLOAT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
MPI_Recv(&alpha2, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
MPI_Recv(&baseA, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
area = areaTri(baseA, alpha1, alpha2);
my_rank = my_rank + i;
}

printf("a = %.2f, alpha1 = %d, alpha2 = %d \n", c, a, b);
printf("Area of %d triangles is %.2f\n", my_rank, area);
}


MPI_Finalize();
return 0;
}
float areaTri (int base, float alpha1, float alpha2){
float area = pow(base, 2) * (sin(alpha1) * sin(alpha2)/sin(alpha1 +alpha2));

return area;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education