Question

In: Computer Science

In C, create a program that displays the minimum and maximum values stored in a data...

In C, create a program that displays the minimum and maximum values stored in a data file "datafile.txt". Use the following function prototype:  void minmaxarray(float value, float *min, float *max);

Solutions

Expert Solution

#include<stdio.h>
#include<string.h>
#include <ctype.h>

//crate a file with number
void createFile()
{
FILE *fp;
char ch;
int i=0;
char str[100] = "14\n15\n20\n53\n50\n70\n17\n34\n45\n12";
fp = fopen("datafile.txt", "w");
fputs(str, fp);
fclose(fp);
}

//function to read the values from a file and put into array
void readFile(float array[])
{
//declaration of file type pointer
FILE *fp;
  
//open file in read mode
fp = fopen("datafile.txt", "r");

float num;
int i=0;
while (!feof (fp))
{
fscanf (fp, "%f", &num);
array[i] = num;
i++;
}
  
//close file
fclose(fp);
}

//function to find the minmum and maximum value
void minmaxarray(float value[], float *min, float *max)
{
*min = value[0];
*max = value[0];
for(int i=1; i<10; i++)
{
if(*min>value[i])
*min = value[i];
if(*max<value[i])
*max = value[i];
i++;
}
}

int main()
{
//array declaration
float array[10];
float min, max;
createFile();
  
//function calling
readFile(array);
minmaxarray(array, &min, &max);
  
//display the result
printf("Minimum = %.2f", min);
printf("\nMaximum = %.2f", max);

return 0;
}

OUTPUT:

datafile.txt


Related Solutions

1-A ________ displays the minimum, first quartile, median, third quartile, and the maximum of a data...
1-A ________ displays the minimum, first quartile, median, third quartile, and the maximum of a data set. scatter plot, contingency table, box plot, stacked column chart. which one is correct? 2- The importance of sampling, from a managerial perspective, is to ________. obtain information to draw a valid inference about a population calculate the population parameters accurately test the correlation between the values of the population find all the defective products in the population. 3- If all the college students...
C++ Create a program that checks whether a number is a prime number and displays its...
C++ Create a program that checks whether a number is a prime number and displays its factors if it is not a prime number. Console Prime Number Checker Please enter an integer between 1 and 5000: 5 5 is a prime number. Try again? (y/n): y Please enter an integer between 1 and 5000: 6 6 is NOT a prime number. It has 4 factors: 1 2 3 6 Try again? (y/n): y Please enter an integer between 1 and...
Write a C program that creates a structure and displays its content. • Create a struct...
Write a C program that creates a structure and displays its content. • Create a struct that will be used to hold a student's name, age, and year in school (Freshman, Sophomore, Junior, or Senior) • Within function main, dynamically allocate space to hold the structure and assign a pointer to point to the memory space allocated • Read in (from the keyboard) the student's name, age, and year in school • Create a separate function with the prototype: void...
Write a C program/code that prompts the user for a minimum min and a maximum max....
Write a C program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
A maximum of 300 nodes are to be stored in a hashed data structure. Give the...
A maximum of 300 nodes are to be stored in a hashed data structure. Give the size of the primary storage area that would maximize the performance of the structure.
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an inpatient or an outpatient. If the patient was an inpatient, the following data should be entered: The number of days spent in the hospital The daily rate Hospital medication charges Charges for hospital services (lab tests, etc.) The program should ask for the following data if the patient was...
Find the absolute maximum and absolute minimum values of the function, if they exist, on the...
Find the absolute maximum and absolute minimum values of the function, if they exist, on the indicated interval. 6) f(x) = x 4 - 32x 2 + 2; [-5, 5]
The minimum and maximum values of the coefficient of determination r2 are, respectively, A. 0 and...
The minimum and maximum values of the coefficient of determination r2 are, respectively, A. 0 and 1 B. −1 and 1 C. −1 and 0 D. 0 and +∞ The following data represent a random sample of earwig density (x) and the proportion of males that have forceps (y). Earwig Density Proportion of Males with Forceps 0.25 0.05 5.3 0.1 12.6 0.67 22 0.19 25.4 0.04 32.3 0.53 Which of the following is the correlation coefficient? A. 0.33 B. 0.17...
In C++, write a function that returns the average of all the values stored in an...
In C++, write a function that returns the average of all the values stored in an integer array (called arr) of size n. The return type of the function should be double. Test this function in the main program.
Using a minimum of 2 classes create a java program that writes data to a file...
Using a minimum of 2 classes create a java program that writes data to a file when stopped and reads data from a file when started. The data should be in a readable format and the program should work in a way that stopping and starting is irrelevant (e.g. all data doesn't have to save just the important elements.) Program should be unique and semi-complex in some way.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT