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/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.
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...
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.
c++ A program that displays the status of an order. a) Program uses 2 functions (in...
c++ A program that displays the status of an order. a) Program uses 2 functions (in addition to main ()). b) The first function asks the user for the data below and stores the input values in reference parameters. c) Input data from user: # of spools ordered, # of spools in stock, any special shipping & handling charges over and above the $10 rate. d) The second function receives as arguments any values needed to compute and display the...
In this exercise, you will create a program that displays the amount of a cable bill....
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer, as shown in Figure 10-30. For a residential cus- tomer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. If necessary, create a...
In this exercise, you will create a program that displays the amount of a cable bill....
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer shown in figure 10-30. For a residential customer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. Enter your C++ instructions into the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT