Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this part, write a complete C program that opens the data file called hugcda

ID: 3931423 • Letter: F

Question

For this part, write a complete C program that opens the data file called hugcdata.txt which was previously generated on your computer in part 1. Your program should access the data in the data file and successfully perform the following calculations, printing the results to the screen for the user to see: Add up all three hundred data values. Find the largest data value in the data set. Find the smallest data value in the data set. Determine how many data values fall inside of the following data ranges: 1 lessthanorequalto N lessthanorequalto 5, 6 lessthanorequalto N lessthanorequalto 10, 11 lessthanorequalto N lessthanorequalto 15 and 16 lessthanorequalto N lessthanorequalto 20. (If your data was generated properly in pan 1, these four counted values should add up to 300!) This part of the assignment should not be included in the same .c file as part 1 ! Be sure to include some user comments at the top of the program, and email the file to your instructor. Since Kirkwood's email is not too friendly with .c files, just copy and paste your program into the message of the email.

Explanation / Answer

Here is the code for you:

#include <stdio.h>
#define SIZE 300
int main()
{
FILE *fp = fopen("hugedata.txt", "r");
int array[SIZE];
for(int i = 0; i < SIZE; i++)
fscanf(fp, "%i", &array[i]);
fclose(fp);
int sum = 0;
for(int i = 0; i < SIZE; i++)
sum += array[i];
int large, small;
large = small = array[0];
for(int i = 1; i < SIZE; i++)
{
if(array[i] > large)
large = array[i];
if(array[i] < small)
small = array[i];
}
int cat1 = 0, cat2 = 0, cat3 = 0, cat4 = 0;
for(int i = 0; i < SIZE; i++)
if(array[i] >= 1 && array[i] < 5)
cat1++;
else if(array[i] >= 6 && array[i] < 10)
cat2++;
else if(array[i] >= 11 && array[i] < 15)
cat3++;
else if(array[i] >= 16 && array[i] < 20)
cat4++;
printf("The largest data value in the data set is: %i ", large);
printf("The smallest data value in the data set is: %i ", small);
printf("The total numbers in the range 1 <= N < 5 is: %i ", cat1);   
printf("The total numbers in the range 6 <= N < 10 is: %i ", cat2);
printf("The total numbers in the range 11 <= N < 15 is: %i ", cat3);
printf("The total numbers in the range 16 <= N < 20 is: %i ", cat4);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote