一道C语言程序设计面试
对于一次考试成绩进行统计,考M科,(如六科,语文、政治、数学、物理、化学、外语),有N人(如10000人)参加。统计要求;每个人的总成绩(total)
每科的平均成绩
以个人总分的成绩排序,最高分排在第一名,最后输出的表格如下所示。
名次考号姓名语文政治数学物理化学外语总分
---------------------------------------------------------------------------------------
1
2
3
---------------------------------------------------------------------------------------
平均成绩
怎么没人回复?
:( 正好今天公司没活干~遇到我算你幸运~这种题应该发到开发群里去...#include <stdio.h>
#include <time.h>
#define STD_NUM 3
#define SBJ_NUM 6
void SetScore();
void PrintScore();
void PrintAVG();
typedef struct Student{
double allscore;
float score;
}Student;
int main()
{
Student s;
char *objarr = {"eng","chs","math","phy","gov", "gym"};
/*设置成绩*/
SetScore(s);
/*输出成绩*/
PrintScore(s, objarr);
/*输出平均成绩*/
PrintAVG(s);
getch();
}
void SetScore(Student s)
{
int i;
int j;
for (i = 0; i < STD_NUM; i++)
{
s.allscore = 0;
srand( (unsigned)(i+1));/*设置随机种子*/
for (j = 0; j < SBJ_NUM; j++)
{
s.score = rand()%100; /*0-100随机数*/
s.allscore += s.score;
}
}
getch();
}
void PrintScore(Student s, char *p)
{
int i;
int j;
Student stutemp;
/*排序*/
for (i = 0; i < STD_NUM-1; i++)
{
for (j = i+1; j < STD_NUM; j++)
if (s.allscore < s.allscore)
{
stutemp = s;
s = s;
s = stutemp;
}
}
for (i = 0; i < STD_NUM; i++)
{
/*打印表头*/
if (i == 0)
{
printf("\t");
for (j = 0; j < SBJ_NUM; j++)
{
printf("%s\t", p);
}
printf("all\n");
}
printf("%d:\t", i+1);
/*开始打印成绩数据 */
for (j = 0; j < SBJ_NUM; j++)
{
printf("%2.2f\t", s.score);
}
printf("%f\n", s.allscore);
}
}
void PrintAVG(Student s)
{
int i;
int j;
double all = 0;
float avg = 0;
printf("平均成绩");
for (i = 0; i < SBJ_NUM; i++)
{
all = 0;
for (j = 0; j < STD_NUM; j++)
{
all += s.score;
}
avg = all/STD_NUM;
printf("%2.2f\t", avg);
}
}
谢谢了!
呵呵,虽然有很多错误,但还是要非常感谢你的:P 呵呵~可能是字体原因吧~我在Win-TC下运行出结果了... 长见识了,谢谢
页:
[1]