Write a program that calculates the area of rectangle. Your program should have
ID: 3670373 • Letter: W
Question
Write a program that calculates the area of rectangle. Your program should have functions named get_input, calculate, and display. get_input: prompts user for length and width calculate: calculates and returns the area display: displays the area to a user.
something wrong with my code..please hlep!
#include<stdio.h>
#include<conio.h>
void get_input(float *length, float *width);
void display(float);
float calulate(float length, float width);
int main()
{
int length, width, area;
printf(" Enter the length of Rectangle :");
scanf("%d", &length);
printf(" Enter the width of Rectangle :");
scanf("%d", &width);
area = length * width;
printf(" Area of Rectangle : %d", area);
getchar();
getch();
return 0;
}
void get_input(float *length, float width)
{
get_input(&length, &width);
}
float calulate(float length, float width)
{
return length*width;
}
void display(float area){
display(area);
}
Explanation / Answer
#include<stdio.h>
void get_input(float *length, float *width);
void display(float);
float calulate(float length, float width);
int main()
{
float length, width, area;
get_input(&length, &width);
area = calulate(length,width);
display(area);
return 0;
}
void get_input(float *length, float *width)
{
printf(" Enter the length of Rectangle :");
scanf("%f", length);
printf(" Enter the width of Rectangle :");
scanf("%f", width);
}
float calulate(float length, float width)
{
return length*width;
}
void display(float area){
printf(" Area of Rectangle : %f", area);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.