Problem #2 Write a C program that uses an array and reads up to 50 floating poin
ID: 651661 • Letter: P
Question
Problem #2
Write a C program that uses an array and reads up to 50 floating point values from the user and then calculates their average. In addition to calculating the average, the program will also compute the absolute deviation of each numerical quantity from the average using the formula: deviation = | xvaluei ? average |, where i= 1, 2, .., n
The program should use a while loop to, check the process of putting number in the array 2 times so that it is know that the quantity is variable up to 50 pieces of data, first 5 values are put in and next 7 values are put in. The output display of numbers should be with 2 decimal places. Use of the Math header file built-in functions is mandatory where applicable.
DO NOT USE <ISOSTREAM>, USE <STDIO.H> INSTEAD.
Explanation / Answer
Hope this may helps you....
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <fstream>
#include <stdio.h>
using namespace std;
main ()
{
while (inFile >> num)
{
if (count3 == 0)
{
max = num;
min = num;
}
if (num > max)
{
max = num;
}
if (num < min)
{
min = num;
}
count3++;
sum += num;
totSum += num;
count1++;
count2++;
}
int main()
{
float Max, Min, num;
int i;
FILE *fi;
FILE *fo;
if ((fi = fopen("a3.txt")) == 0)
{
printf("error opening file ");
return 1;
}
fscanf(fi, %f, & Max);
Min = Max;
for (i = 0; i < 8; i ++)
{
if (num > Max)
{
Max = num;
}
if (Temp < Min)
{
Min = num;
}
}
fclose(fi);
if ( (fo=fopen("a3.txt")) == NULL )
{
printf("ERROR opening file ");
return 1;
}
cout << "The minimum value found is %f" << Min;
cout << "The maximum = " << Max;
fclose(fo);
return 0;
}
system ("Pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.