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 |
Why static variable is used in c?
In C language what is a 'dangling pointer'?
What is the scope of static variables?
how can i get the output 54321 4321 321 21 1 in c programming........???? pls help......
How can you allocate arrays or structures bigger than 64K?
If we give two names then this displays the connection between the two people. It is nothing but flames game
Can one function call another?
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above
Add Two Numbers Without Using the Addition Operator
What's a "sequence point"?
What is int main () in c?
Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(ā%cā, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command.
1 Answers BladeLogic, Infosys,