how can i calculate mean,median,mode by using c program
Answer / 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 |
if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
How do I access command-line arguments?
What is actual argument?
void main() {int a[5],i,b=16; for(i=0;i<5;i++) a[i]=2*i; f(a,5,b); for(i=0;i<5;i++) printf("\n %d",a[i]); printf("\n %d",b); } f(int *x,int n,int y) { int i; for(i=0;i<n;i++) *(x+i)+=2; y=y+2; }wat r the errors in the prg.and improvise the prg to get o/p.?
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
What is the difference between if else and switchstatement
What is the use of getchar functions?
how to find the kth smallest element in the given list of array elemnts.
write a c/c++ programthat connects to a MYSQL server and checks if the INNoDB plug in is installed on it.If so your program should print the total number of disk writes by MYSQL.
What is volatile variable how do you declare it?
What does c in a circle mean?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?