int main( ) {
   double demoset[] = { 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 } ;
   int demosize = sizeof demoset / sizeof *demoset ;
   std::cout << "The standard deviation of\n" ;
   std::copy( demoset , demoset + demosize , std::ostream_iterator<double>( std::cout, " " ) ) ;
   std::cout << "\nis " << standard_dev( demoset , demoset + demosize ) << " !\n" ;
   return 0 ;
}
Exemplo n.º 2
0
int main(void)

{

/************************************* Variables ***************************************/

/* k will act as a counter. REMEMBER to reinitialize it to 0 */

int i, score, minscore, maxscore;     
int scores[100];
float avg, stdv;
char filename[20];
FILE *file;

/********************* Ask user which file using string variable ***********************/

printf("Enter a file name >>> ");
scanf("%s", filename);
printf("\n\n");
file = fopen(filename, "r");

/****************************** Reading scores to array ********************************/

i=0;

while (fscanf(file, "%d", &score) != EOF) {

	scores[i] = score;
	i++;  /* i is now also the number of scores in the array */
	
}

/************************************ Function Calls ***********************************/

avg = average(i, scores);
stdv = standard_dev(i, scores, avg);
minscore = minscore = minimum(i, scores);
maxscore = maxscore = maximum(i, scores);

/************************************* Printing ****************************************/

printf("The average of the values in this file is %f.\n\n", avg);
printf("The standard deviation of the values in this file is %f.\n\n", stdv);
printf("The minimum score of the values in this file is %d.\n\n", minscore);
printf("The maximum score of the values in this file is %d.\n\n", maxscore);

/***************************************************************************************/

return (0);

}