These problems involve computing an area or a volume using input from the user.
ID: 662957 • Letter: T
Question
These problems involve computing an area or a volume using input from the user. Each program should include a prompt to the user to enter the variables needed. Save each program separately in one folder, zip up the folder and turn it in on Blackboard/Learn under the Extra Credit Calculations Ch2 assignment. Add error checking into each program for an extra 0.5 points of extra credit for the assignment. This particular extra credit assignment is worth 2 points on your Midterm 1 exam since it has almost 10 problems.
Write a program to compute the area of a rectangle with side a and b.
AreaRectangle = a * b
Write a program to compute the area of a triangle with base b and height h.
AreaTriangle =
Explanation / Answer
Program 1: program to compute the area of a rectangle with side a and b
#include<stdio.h>
#include<conio.h>
int main() {
int length, breadth, area;
printf(" Enter the Length of Rectangle : ");
scanf("%d", &length);
printf(" Enter the Breadth of Rectangle : ");
scanf("%d", &breadth);
area = length * breadth;
printf(" Area of Rectangle : %d", area);
return (0);
}
Program 2: Program to compute the area of a triangle with base b and height h.
#include<stdio.h>
void main()
{
float b, h, area;
printf("Enter a base & height of tringle : ");
scanf("%f %f", &b, &h);
area = (b*h)/2;
printf("The area of the tringle is %.2f", area);
}
Program 3: program to compute the area of a circle with radius r
#include<stdio.h>
int main() {
float radius, area;
printf(" Enter the radius of Circle : ");
scanf("%d", &radius);
area = 3.14 * radius * radius;
printf(" Area of Circle : %f", area);
return (0);
}
Program 4: program to compute the area of a sector of a circle where ? is the angle in radians between the radii.
#include<stdio.h>
int main() {
int rad;
float PI = 3.14, area, ci;
printf(" Enter radius of circle: ");
scanf("%d", &rad);
area = PI * rad * rad;
printf(" Area of circle : %f ", area);
ci = 2 * PI * rad;
printf(" Circumference : %f ", ci);
return (0);
}
I will try rest of programs and update you soon
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.