Define a structure for a rectangular prism (name the structure prism), which has
ID: 3654511 • Letter: D
Question
Define a structure for a rectangular prism (name the structure prism), which has the following members: length, width, height, surface area and volume of the prism. Write a C program that has a main and one function. In main, length, width and height of a rectangular prism are input from keyboard (scanf), call function area, print the area. In function area(prismPtr), the surface area is calculatedExplanation / Answer
#include struct prism { float length; float width; float height; float area; float volume; }; float area(struct prism *prt); int main() { struct prism p; printf("Enter lenght, width and hight of the prism "); scanf("%f %f %f",&p.length, &p.width, &p.height); p.area=area(&p); printf("Surface area of prism is : %f", p.area); return 0; } float area( struct prism *ptr) { ptr->area=2*(ptr->length*ptr->width+ptr->length*ptr->height+ptr->width*ptr->height); return ptr->area; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.