midnight knight
Journeyman
- Joined
- Dec 7, 2022
- Posts
- 25
- Solutions
- 1
- Reaction
- 2
- Points
- 16
Create a C program that does the following:
Here is what I have done so far. Perhaps, I need help in sorting out the numbers I have in the file "RandomExamScores.txt"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 50
void RandomExamScores()
{
FILE *fptr;
fptr = fopen("RandomExamScores.txt", "w");
int count;
int num[SIZE];
int lower = 20, upper = 40;
srand(time(NULL));
for (count = 0; count < SIZE; count++)
num[count] = (rand() % (upper - lower + 1)) + lower;
for(count = 0; count < SIZE; count++)
{
if(count % 10 == 0)
fprintf(fptr, "\n");
fprintf(fptr, "%4d ", num[count]);
}
}
int main()
{
fprintf(fptr, "Random Exam Scores: \n");
RandomExamScores();
fclose(fptr);
}
- Generates 50 random exam scores and then writes the generated scores to the file RandomExamScores.txt in columns of 10. The highest and lowest possible scores are 40 and 20, respectively.
- Reads the exam scores from the file RandomExamScores.txt, sorts the exam scores in increasing order, and writes the sorted scores to the file SortedExamScores.txt.
- Determines the mean, median, and mode of the exam scores.
- Appends to the file SortedExamScores.txt the results in (3).
Here is what I have done so far. Perhaps, I need help in sorting out the numbers I have in the file "RandomExamScores.txt"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 50
void RandomExamScores()
{
FILE *fptr;
fptr = fopen("RandomExamScores.txt", "w");
int count;
int num[SIZE];
int lower = 20, upper = 40;
srand(time(NULL));
for (count = 0; count < SIZE; count++)
num[count] = (rand() % (upper - lower + 1)) + lower;
for(count = 0; count < SIZE; count++)
{
if(count % 10 == 0)
fprintf(fptr, "\n");
fprintf(fptr, "%4d ", num[count]);
}
}
int main()
{
fprintf(fptr, "Random Exam Scores: \n");
RandomExamScores();
fclose(fptr);
}