Write a program that will input three decimal numbers from a text file named in.
ID: 3544830 • Letter: W
Question
Write a program that will input three decimal numbers from a text file named in.txt and compute the following statistics about them:
The smallest number
The largest number
The sum of the numbers
The mean (average) of the numbers
The median of the numbers
It will output the above statistics in an output text file named out.txt.
It will also output the above statistics to screen (cout).
Data
Input file in.txt contents:
20.2
6.2
7.2
Output file out.txt content:
Smallest Number: 6.2
Largest Number: 20.2
Sum of Numbers: 33.6
Mean of Numbers: 11.2
Median of Numbers: 7.2
Explanation / Answer
#include using namespace std; int main() { FILE *fp; fp = fopen("a.txt","r"); int a,b,c; fscanf("%d",&a); fscanf("%d",&b); fscanf("%d",&c); float min,max,sum=0,mean=0,median=0; sum = a+b+c; mean = (a+b+c)/3.0; if(a>b && a>c) { max=a; } if(b>c && b>a) { max=b; } if(c>b && c>a) { max=c; } if(aRelated 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.