how can i calculate mean,median,mode by using c program

Answer Posted / devraj the king of the kings

#include
#include

#define NULL 0

FILE*scores;

main()
{
int scores[50];
int numberOfScores = 0;

/*Function Definitions*/
void readFile (int a[], ∫);
void calculateMean (int a[]);
void sortArray (int a[], int);
void calculateMedian (int a[]);
void calculateMode (int a[]);

}
/*Read the file with scores*/

void readFile (int a[], &numberOfScores);

{

int flag = TRUE;

scoresFile = fopen("scores.txt","r");

if(scoresFile == NULL)

{
printf("\nERROR-cannot open the file\n");
}

if loop to read scores from file
while(flag)
}

/*read each entry from file*/
fscanf(scoresFile, "%d", a[numberOfScores]);
numberOfScores = numberOfScores +1;
}

if(numberOfScores , 50)
{
printf("\nERROR-Less than 50 scores available");
}
}
fclose(scoresFile);
}
/*===============================================================*/
calculateMean(int 1[], int numberOfScores)
{
int i, total;
float mean;
for(i = 0; i < numberOfScores; i++)
{
total = total + a[i];
)

mean = total/numberOfScores;

printf("Mean of the Scores: %f" , mean);
}

*/================================================================*/
void sort(inta[], int array_size)
{
int i, j, temp;
for (i =(array_size-1); i>= 0; i-)
{
for (j=1; j<= i; j++)
{
if(a[j-1] > a[j])
{
temp = a[j-1];
a[j-1] = a[1];
a[1] = temp;
}

}
}
*/================================================================*/

calculateMedian(int a[])
{
float median;
median = (a[24] + a[25])/2;
printf("Median: %f", median);
}

*/================================================================*/

calculateMode(inta[])
{

int multi[50][2];
int j, k, l;
int mode, higher, temp;

/*initialize the array second element to 0*/
for(k=0; k<50; k++)
{
multi[k][0] = 0;
multi[k][1] = 0;
}

/*pass the original array and store array into multidimensional if there are no entries for that value*/

for(j=0; j<50; j++)
{

score =a[j];
for(k = 0; k< 50; k++)
(
if(score == multi[k][0]
{
multi[k][1] = multi[k][1] + 1;
}
}
}
higher = multi[0][1];

for(j=0; j<50; j++)
{
if(higher , multi[j][1])
higher= multi[j][1]l
}

printf("Mode of the scores: %d", higher);

}

Is This Answer Correct ?    5 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of variables in c?

774


What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.

2023


Explain that why C is procedural?

896


how to introdu5ce my self in serco

1735


Why shouldn’t I start variable names with underscores?

838


What is a null pointer in c?

834


if p is a string contained in a string?

1612


Differentiate between null and void pointers.

870


A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

923


Write a program to swap two numbers without using third variable in c?

861


c program to compute AREA under integral

2076


How do we open a binary file in Read/Write mode in C?

968


Explain the difference between structs and unions in c?

762


What is boolean in c?

818


What are pointers really good for, anyway?

807