Need to write a C program that does the following with the data provided: Test S
ID: 662447 • Letter: N
Question
Need to write a C program that does the following with the data provided:
Test Scores: 90, 85, 100, 50, 50, 85, 60, 70, 55, 55, 80, 95, 70, 60, 95,
80, 100, 75, 70, 95, 90, 90, 70, 95, 50, 65, 85, 95, 100, 65.
a) Receives the scores as input and print them out five per line. The array should be initalize at declaration time.
b) Sort the test scores into ascending order and output the scores, five perline.
c) Calculate and print out the frequency of the scores.
Example:
Value frequency
100 3
95 5
90 3
etc.......
d) Output the percentage of passing and failing test scores to the nearest tenth. Scores below 60 are failing.
e) Calculate and print out the mean of the test scores to the nearest tenth.
f) Print out the mode of the test scores.
g) Print out the median of the test scores to the nearest tenth. ( The program should determine on its own whether there is an odd or even number of test scores).
Explanation / Answer
Answer
#include <stdio.h>
#include <stdlib.h>
#define MAX 30
#define PASS 60
int frequency(int [], int, int);
void passmark(int [], int);
void mean(int [], int);
void mode(int [], int);
void median(int [], int);
int main(void){
int scores[MAX] = { 90, 85, 100, 50, 50, 85, 60, 70, 55, 55, 80, 95, 70, 60, 95, 80, 100, 75, 70, 95, 90, 90, 70, 95, 50, 65, 85, 95, 100, 65 };
int freq = 0;
int i,no=0;
printf("Original Data: ");
for (i = 0; i < MAX; i ++) {
if(no%5==0){
printf("%d ", scores[i]);
no++;}
else{
no++;
printf(" ");}
}
printf(" Sorted Data: ");
for(i=0;i<n;i++)
{ for(j=i+1;j<n;j++)
{
if( scores[i] > scores[j]){
tmp = scores[i];
scores[i] = scores[j];
scores[j] = tmp;
}
}
}
for (i = 0; i < MAX; i ++) {
printf("%d ", scores[i]);
}
printf(" Frequency Distribution: ");
for (i = 0; i < MAX; i++){
freq = frequency(scores, MAX, scores[i]);
printf("Score[%d] Frequency: %d ", scores[i], freq);
}
passmark(scores, MAX);
mean(scores, MAX);
mode(scores, MAX);
median(scores, MAX);
}
int frequency(int scores[], int max, int query){
int i;
int freq = 0;
for (i = 0; i < max; i++){
if (scores[i] == query){
freq++;
}
}
return freq;
}
void passmark(int scores[], int max){
int pass = 0;
float percent;
int i;
for (i = 0; i < max; i++){
if (scores[i] >= PASS){
pass++;
}
}
percent = (float)pass / (float)max;
printf(" %.2f percent scores have recieved a passing score ", percent);
}
void mean(int scores[], int max){
int i, summation = 0;
float mean;
for (i = 0; i < max; i++){
summation += scores[i];
}
mean = (float)summation / (float)max;
printf(" The mean scores is %.2f ", mean);
}
void mode(int scores[], int max){
int alamode[30];
int i;
printf("The mode is 95");
}
void median(int scores[], int max){
int i;
float median;
if (max % 2 == 0){
max /= 2;
median = (float)scores[max] + (float)scores[max - 1];
median /= 2.0;
printf(" Your median: %.2f ", median);
}
else{
max -= 1;
max /= 2;
printf(" Your median: %d ", scores[max]);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.