Write a C program that will read floating point numbers from two files weight.tx
ID: 3650444 • Letter: W
Question
Write a C program that will read floating point numbers from two files weight.txt and height.txt.Read one weight number from weight.txt and one weight number from height.txt.Then compute BMI=weight/(Height*height).use while loop to get the numbers and write the table to a file called bmi.txt.1)You can assume that two files contain the same number of floating point numbers.Your program should end if fscanf reaches the end of either of the two files.
2)Include labels for the table.the table should be formatted
3)Print all values with 2 digits after the decimal point.
Explanation / Answer
please rate - thanks
message me any questions, I will answer, and explain
#include <stdio.h>
int main()
{
FILE *weight;
FILE *height;
FILE *output;
float h,w,b;
weight = fopen("weight.txt","r");
if(weight == NULL)
{ printf("Unable to open weight file 1 ");
getch();
return 0;
}
height = fopen("height.txt","r");
if(weight == NULL)
{ printf("Unable to open height file 1 ");
getch();
return 0;
}
output=fopen("bmi.txt","w");
fprintf(output,"Height Weight BMI ");
while(fscanf(weight,"%f",&w)==1&&fscanf(height,"%f",&h)==1)
{b=w/(h*h);
fprintf(output,"%5.2f%8.2f%8.2f ",h,w,b);
}
fclose(height);
fclose(weight);
fclose(output);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.