您的足迹:首页 > 经验技术 >C语言技能考核题目-附源码

C语言技能考核题目-附源码

山野哥的期末作业,我也写着玩玩,写的不好有点乱,请见谅。。。

要求:

2000.png

 

代码:

#include <stdio.h>
#include <process.h>

#define N 100
#define NAME "Lance"

char * sjyGrade(float flScore);

int main()
{
	printf("%s的学生成绩处理程序\n",NAME);

	int sjyNum=0;
	char sjyName[N][10];
	int sjyScore[N][5];
	float sjyAvg[N];//每人总平均分
	float sjySubj[5]={0,0,0,0,0};//全员五门平均分
	int sjyIndex[N];
	char strPrintOut[2048];
	printf("请输入要处理的学生的人数(3~100):");
	scanf("%i",&sjyNum);
	if(sjyNum>N||sjyNum<3) 
	{
		printf("您输入的要处理的学生人数不符合要求!");
		system("pause");
		return 0;
	}
	int iCo;
	for(iCo=0;iCo!=sjyNum;iCo++)
	{
		printf("请输入第%i名学生的姓名:",iCo+1);
		scanf("%s",&sjyName[iCo]);
		printf("语文分数:");
		scanf("%i",&sjyScore[iCo][0]);
		printf("数学分数:");
		scanf("%i",&sjyScore[iCo][1]);
		printf("政治分数:");
		scanf("%i",&sjyScore[iCo][2]);
		printf("英语分数:");
		scanf("%i",&sjyScore[iCo][3]);
		printf("综合分数:");
		scanf("%i",&sjyScore[iCo][4]);
		sjyAvg[iCo]=float(float(sjyScore[iCo][0])+float(sjyScore[iCo][1])+float(sjyScore[iCo][2])+float(sjyScore[iCo][3])+float(sjyScore[iCo][4]))/5;
		printf("第%i名学生成绩输入完毕,平均分%.1f!\n==========================\n",iCo+1,sjyAvg[iCo]);
	}
	for(iCo=0;iCo!=sjyNum;iCo++)
	{
		sjySubj[0]=sjySubj[0]+sjyScore[iCo][0];
		sjySubj[1]=sjySubj[1]+sjyScore[iCo][1];
		sjySubj[2]=sjySubj[2]+sjyScore[iCo][2];
		sjySubj[3]=sjySubj[3]+sjyScore[iCo][3];
		sjySubj[4]=sjySubj[4]+sjyScore[iCo][4];
	}
	sjySubj[0]=sjySubj[0]/sjyNum;
	sjySubj[1]=sjySubj[1]/sjyNum;
	sjySubj[2]=sjySubj[2]/sjyNum;
	sjySubj[3]=sjySubj[3]/sjyNum;
	sjySubj[4]=sjySubj[4]/sjyNum;
	//printf("\n%s\n",strPrintOut);
	char strPrintOutA[2048];
	for(iCo=0;iCo!=sjyNum;iCo++)
	{
		sjyIndex[iCo]=0;
		int iTest=0;
		for(iTest=0;iTest!=sjyNum;iTest++)
		{
			if(sjyAvg[iCo]>sjyAvg[iTest]) sjyIndex[iCo]++;
		}
		sjyIndex[iCo]=sjyNum-sjyIndex[iCo];
	}
	
	sprintf(strPrintOut,"===================================\n姓名\t语文\t数学\t政治\t英语\t综合\t平均分\t级别\t名次\n");
	for(iCo=0;iCo!=sjyNum;iCo++)
	{
		sprintf(strPrintOut,"%s%s\t%i\t%i\t%i\t%i\t%i\t%.1f\t%s\t%i\n",strPrintOut,sjyName[iCo],sjyScore[iCo][0],sjyScore[iCo][1],sjyScore[iCo][2],sjyScore[iCo][3],sjyScore[iCo][4],sjyAvg[iCo],sjyGrade(sjyAvg[iCo]),sjyIndex[iCo]);
	}
	sprintf(strPrintOut,"%s-----------------------------------\n",strPrintOut);
	sprintf(strPrintOut,"%s平均\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",strPrintOut,sjySubj[0],sjySubj[1],sjySubj[2],sjySubj[3],sjySubj[4]);
	system("cls");
	printf("%s的学生成绩处理程序\n",NAME);
	printf("\n%s\n",strPrintOut);
	return 0;
}

char * sjyGrade(float flScore)
{
	char strTemp1[25];
	int iSwi=0;
	sprintf(strTemp1,"%f",flScore/10);
	sscanf(strTemp1,"%i.%*i",&iSwi);
	switch(iSwi)
	{
	case 0:
		return "不及格";
	case 1:
		return "不及格";
	case 2:
		return "不及格";
	case 3:
		return "不及格";
	case 4:
		return "不及格";
	case 5:
		return "不及格";
	case 6:
		return "及格";
	case 7:
		return "中等";
	case 8:
		return "良好";
	case 9:
		return "优秀";
	}
	return "优秀";
}

 

本博客所有文章如无特别注明均为原创。作者:Lance.Moe复制或转载请以超链接形式注明转自 Lance's Blog
原文地址《C语言技能考核题目-附源码

相关推荐

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(4)

process.h这个头文件是干什么用的0.0
oott123 4年前 (2013-07-22) 回复
@oott123:因为有这个system("pause");,所以得include那个头文件
Lance 4年前 (2013-07-26) 回复
3q~~~话说羊,最好不要用system("pause");,用getchar();
sy 4年前 (2013-06-28) 回复
@sy:嗯,控制台程序现在也不是经常写,那个排名的函数我是不是写的特2B。。没学过算法。。
Lance 4年前 (2013-07-02) 回复