PLEASE SOLVE THIS PROBLEM WITH C PROGRAMMING NOT C++. 1. Write a program that ca
ID: 673272 • Letter: P
Question
PLEASE SOLVE THIS PROBLEM WITH C PROGRAMMING NOT C++.
1. Write a program that calculates the area of a trapezoid given its two bases and height. Program should ask for base1, base2 and height and output the area on screen. It should give error messages when bases or height are negative and/or zero.
Useful equation A = (b1 + b2)/2 * h
Example output1:
Please enter the value of base 1, base 2 and height separated by a space
1 1 1
The area of your trapezoid is: 1
Example output2:
Please enter the value of base 1, base 2 and height separated by a space
1 1 0
A trapezoid cannot have 0 height.
Please enter the value of base 1, base 2 and height separated by a space
Explanation / Answer
#include <stdio.h>
int trapezoid(int b1,int b2,int h)
{
return ((b1+b2)/2)*h;
}
int main()
{
int b1,b2,h;
printf("Please enter the value of base 1, base 2 and height separated by a space ");
scanf("%d",&b1);
scanf("%d",&b2);
scanf("%d",&h);
printf("The area of your trapezoid is : %d",trapezoid(b1,b2,h));
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.