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



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

Post New Answer

More C Interview Questions

Find greatest of two numbers using macro

4 Answers   Bosch, Siemens,


If I want to initialize the array like. int a[5] = {0}; then it gives me all element 0. but if i give int a[5] = {5}; then 5 0 0 0 0 is ans. what will I do for all element 5 5 5 5 5 in a single statement???

3 Answers   Amdocs, IBM,


#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

0 Answers   Wilco,


player is good if the following conditions are satisfied: He is either from “India”, “Japan” or “Korea” He has a minimum of 3 years of experience He has won at least 3 major tournaments, and one of them must be "World Championship Tournament". He must know more than 10 techniques. (but see next question) If he knows less than 10 techniques, then he must be a world champion. His name contains at least 3 words. For example "Sachin Tendulkar" will not meet this condition. Write a method: boolean isGoodPlayer(String name, String country, int yearsExperience, String[] majorTournamentsWon, String[] techniques, boolean isWorldChampion) name country yearsExperience majorTournamentsWon techniques isWorldChampion

1 Answers  


why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above

0 Answers  






which of the following go out of the loopo if expn 2 becoming false a.while(expn 1){...if(expn 2)continue;} b.while(!expn 1){if(expn 2)continue;...} c.do{..if(expn 1)continue;..}while(expn 2); d.while(!expn 2){if(expn 1)continue;..}

4 Answers   TCS,


When should we use pointers in a c program?

0 Answers  


What is the memory allocated by the following definition ? int (*x)();

2 Answers   ADITI,


FIND THE OUTPUT IF THE INPUT IS 5 5.75 void main() { int i=1; float f=2.25; scanf("%d%f",&i,&f); printf("%d %f",,i,f); } ANSWER IS 5 AND 2.25 WHY?

4 Answers   Wipro,


What is a dynamic array in c?

0 Answers  


#include<stdio.h> int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20

0 Answers  


What is the difference between array and pointer in c?

0 Answers  


Categories