I need help getting the height of the trapezoid and rectangl
I need help getting the height of the trapezoid and rectangle for this python program!!!!!
Solution
#include <stdio.h>
#include<math.h>
int main() // main execution starts
{
int cf,rule,r,a,b; //variables for the operations
printf(\"Choose a function (1,2,3,4,5):\ \"); // prompting user to select funciton
scanf(\"%d\",&cf); // reading the user data
printf(\"Would you like to calculate the area using rectangles, trapezoids, or both? (1, 2, 3):\ \"); // prompting user
scanf(\"%d\",&rule); // reading the data from user
switch(rule) // switch for the desired method or rule
{
case 1: printf(\"How many rectangle do you want:\ \"); // reading data from user
scanf(\"%d\",&r);
printf(\"Choose starting point:\ \");
scanf(\"%d\",&a);
printf(\"Choose ending point:\ \");
scanf(\"%d\",&b);
rectangle(r,a,b); // calling function for rectangel method
break;
case 2:
printf(\"How many trapiziods do you want:\ \"); // reading required data from user
scanf(\"%d\",&r);
printf(\"Choose starting point:\ \");
scanf(\"%d\",&a);
printf(\"Choose ending point:\ \");
scanf(\"%d\",&b);
trapiziodal(r,a,b); // calling trapiziods method by passing r a and b
break;
case 3:
printf(\"How many rectangle/trapiziods do you want:\ \"); // read data from user
scanf(\"%d\",&r);
printf(\"Choose starting point:\ \");
scanf(\"%d\",&a);
printf(\"Choose ending point:\ \");
scanf(\"%d\",&b);
rectangle(r,a,b); // calling both functions
trapiziodal(r,a,b);
break;
}
return 0;
}
void rectangle(int r,int a,int b) // rectangle function here
{
int i;
float c,result=0.0,temp;
c=(b-a)/r; // loading unit scale of graph if a=1 b=2 n=10 then x0=1.1, x1=1.2 ...x10=2.0;
temp=c;
switch(cf) // switch for desired function
{
case 1:
for(i=0;i<r;i++) // loop through all x values
{
result=result+2*power(c,5)+power(c,3)-10*c+2; // function calculation
c=c+temp;
}
result=temp*result;
printf(\"Area by rectangles is:%f \",result); // printing the result
break;
case 2:
for(i=0;i<r;i++)
{
result=result+6*power(c,5)-c+10;
c=c+temp;
}
result=temp*result;
printf(\"Area by rectangles is:%f \",result);
break;
case 3:
for(i=0;i<r;i++)
{
result=result+5*c+3;
c=c+temp;
}
result=temp*result;
printf(\"Area by rectangles is:%f \",result);
break;
case 4:
for(i=0;i<r;i++)
{
result=result+2*power(c,3)+120;
c=c+temp;
}
result=temp*result;
printf(\"Area by rectangles is:%f \",result);
break;
case 5:
for(i=0;i<r;i++)
{
result=result+2*power(c,2);
c=c+temp;
}
result=temp*result;
printf(\"Area by rectangles is:%f \",result);
break;
}
}
void trapiziodal(int r,int a,int b) // trapiziodal implementation
{
int i;
float c,result=0.0,temp,val;
c=(b-a)/r;
val=c/2;
temp=c;
switch(cf)
{
case 1:
for(i=0;i<r;i++)
{
if(i==0 ||i==r-1)
{
result=result+2*(2*power(c,5)+power(c,3)-10*c+2);
c=c+temp;
}
result=result+2*power(c,5)+power(c,3)-10*c+2;
c=c+temp;
}
result=val*result;
printf(\"Area by trapiziodal is:%f \",result);
break;
case 2:
for(i=0;i<r;i++)
{
if(i==0 ||i==r-1)
{
result=result+2*(6*power(c,5)-c+10);
c=c+temp;
}
result=result+6*power(c,5)-c+10;
c=c+temp;
}
result=val*result;
printf(\"Area by trapiziodal is:%f \",result);
break;
case 3:
for(i=0;i<r;i++)
{
if(i==0 ||i==r-1)
{
result=result+2*(5*c+3);
c=c+temp;
}
result=result+(5*c+3);
c=c+temp;
}
result=val*result;
printf(\"Area by trapiziodal is:%f \",result);
break;
case 4:
for(i=0;i<r;i++)
{
if(i==0 ||i==r-1)
{
result=result+2*(2*power(c,3)+120);
c=c+temp;
}
result=result+2*power(c,3)+120;
c=c+temp;
}
result=val*result;
printf(\"Area by trapiziodal is:%f \",result);
break;
case 5:
for(i=0;i<r;i++)
{
if(i==0 || i=r-1)
{
result=result+2*(2*power(c,2));
c=c+temp;
}
result=result+2*power(c,2);
c=c+temp;
}
result=val*result;
printf(\"Area by trapiziodal is:%f \",result);
break;
}
}



