[Plain]
/* Start the comments in the program header (to avoid any problems encountered during the submission of blog posts, the slash used to indicate that the comments have been deleted)
* Copyright and version Declaration of the program
* All rights reserved.
* File name: txt. c
* Author: liuyongshui
* Question: in the array score, the results of a group's C ++ program design will be stored.
* Problem source:
* Completion date: January 1, April 18, 2013
* Version No.: V1.0
*/
# Include <stdio. h>
# Include <math. h>
Float total (float grade [], int num );
Float average (float sum, int num );
Float deviation (float grade [], float ave, int num); // evaluate the deviation
Void max_min (float grade [], int num );
Int main ()
{
Int I;
Int num;
Float sum;
Float ave;
Float dev; // Deviation
Float grade [100];
Printf ("Is there anyone in your class? Summary :");
Scanf ("% d", & num );
Printf ("\ n ");
For (I = 0; I <num; I ++)
{
Printf ("Enter the % 2d score (Press EENTER):", I );
Scanf ("% f", & grade [I]);
}
Sum = total (grade, num );
Printf ("\ n total score: % 0.2f \ n", sum );
Ave = average (sum, num );
Printf ("\ n average score: % 0.2f \ n", ave );
Dev = deviation (grade, ave, num );
Printf ("\ n deviation: % 0.2f \ n", dev );
Max_min (grade, num );
Return 0;
}
// Sum () function declaration
Float total (float grade [], int num) // calculates the total score
{
Int I;
Float sum = 0.0;
For (I = 0; I <num; I ++)
{
Sum + = grade [I];
}
Return sum;
}
// Average () function declaration
Float average (float sum, int num) // calculate the average score
{
Float ave;
Ave = sum/num;
Return ave;
}
// Deviation () function declaration
Float deviation (float grade [], float ave, int num) // evaluate the deviation
{
Int I;
Float seconds = 0.0;
Float dev;
For (I = 0; I <num; I ++)
{
S = s + (grade [I]-ave) * (grade [I]-ave );
}
Dev = sqrt (s/(num-1 ));
Return dev;
}
// Max_min () function declaration
Void max_min (float grade [], int num)
{
Int I;
Int j = 0;
Int l = 0;
Int max_num [2, 100];
Int min_num [100];
Float max;
Float min;
Max = min = grade [0];
For (I = 0; I <num; I ++)
{
If (max <grade [I])
{
Max = grade [I]; // calculates the maximum value.
}
If (min> grade [I])
{
Min = grade [I]; // calculates the minimum value.
}
}
For (I = 0; I <num; I ++)
{
If (max = grade [I])
{
Max_num [j ++] = I; // records the maximum student ID
}
If (min = grade [I])
{
Min_num [l ++] = I; // records the minimum student ID
}
}
Printf ("Maximum score: % 0.2f \ n", max );
Printf ("the highest score is :");
For (I = 0; I <j; I ++)
{
Printf ("% d", max_num [I]);
If (I <J-1) // I <J-1 is printing comma, and vice versa
{
Printf (",");
}
}
Printf ("\ n ");
Printf ("min: % 0.2f \ n", min );
Printf ("the student IDs for the lowest score are :");
For (I = 0; I <l; I ++)
{
Printf ("% d", min_num [I]);
If (I L-1) // I <L-1 is to print a comma. Otherwise, it is not printed.
{
Printf (",");
}
}
Printf ("\ n ");
}
/* Start the comments in the program header (to avoid any problems encountered during the submission of blog posts, the slash used to indicate that the comments have been deleted)
* Copyright and version Declaration of the program
* All rights reserved.
* File name: txt. c
* Author: liuyongshui
* Question: in the array score, the results of a group's C ++ program design will be stored.
* Problem source:
* Completion date: January 1, April 18, 2013
* Version No.: V1.0
*/
# Include <stdio. h>
# Include <math. h>
Float total (float grade [], int num );
Float average (float sum, int num );
Float deviation (float grade [], float ave, int num); // evaluate the deviation
Void max_min (float grade [], int num );
Int main ()
{
Int I;
Int num;
Float sum;
Float ave;
Float dev; // Deviation
Float grade [100];
Printf ("Is there anyone in your class? Summary :");
Scanf ("% d", & num );
Printf ("\ n ");
For (I = 0; I <num; I ++)
{
Printf ("Enter the % 2d score (Press EENTER):", I );
Scanf ("% f", & grade [I]);
}
Sum = total (grade, num );
Printf ("\ n total score: % 0.2f \ n", sum );
Ave = average (sum, num );
Printf ("\ n average score: % 0.2f \ n", ave );
Dev = deviation (grade, ave, num );
Printf ("\ n deviation: % 0.2f \ n", dev );
Max_min (grade, num );
Return 0;
}
// Sum () function declaration
Float total (float grade [], int num) // calculates the total score
{
Int I;
Float sum = 0.0;
For (I = 0; I <num; I ++)
{
Sum + = grade [I];
}
Return sum;
}
// Average () function declaration
Float average (float sum, int num) // calculate the average score
{
Float ave;
Ave = sum/num;
Return ave;
}
// Deviation () function declaration
Float deviation (float grade [], float ave, int num) // evaluate the deviation
{
Int I;
Float seconds = 0.0;
Float dev;
For (I = 0; I <num; I ++)
{
S = s + (grade [I]-ave) * (grade [I]-ave );
}
Dev = sqrt (s/(num-1 ));
Return dev;
}
// Max_min () function declaration
Void max_min (float grade [], int num)
{
Int I;
Int j = 0;
Int l = 0;
Int max_num [2, 100];
Int min_num [100];
Float max;
Float min;
Max = min = grade [0];
For (I = 0; I <num; I ++)
{
If (max <grade [I])
{
Max = grade [I]; // calculates the maximum value.
}
If (min> grade [I])
{
Min = grade [I]; // calculates the minimum value.
}
}
For (I = 0; I <num; I ++)
{
If (max = grade [I])
{
Max_num [j ++] = I; // records the maximum student ID
}
If (min = grade [I])
{
Min_num [l ++] = I; // records the minimum student ID
}
}
Printf ("Maximum score: % 0.2f \ n", max );
Printf ("the highest score is :");
For (I = 0; I <j; I ++)
{
Printf ("% d", max_num [I]);
If (I <J-1) // I <J-1 is printing comma, and vice versa
{
Printf (",");
}
}
Printf ("\ n ");
Printf ("min: % 0.2f \ n", min );
Printf ("the student IDs for the lowest score are :");
For (I = 0; I <l; I ++)
{
Printf ("% d", min_num [I]);
If (I L-1) // I <L-1 is to print a comma. Otherwise, it is not printed.
{
Printf (",");
}
}
Printf ("\ n ");
}