C语言练习之循环小题目

选修某课程的学生有30人,学生信息包括学号和成绩,按学号的高低对学生信息进行排序,统计并输出超过平均分的学生信息;统计该门课程优秀、良好、中等、及格和不及格人数;从键盘上输入一个学号。输出该学号对应的学生信息。

#include 
#include 
#define N 30
int main()
{
	int sum = 0, m, t, number, num[N], score[N], i, j;
	int you = 0, liang = 0, zhong = 0, jige = 0, buji = 0;//定义各个等级的人数
	float average;
	printf("请输入学号和成绩:\n");
	for (i = 0; i < N; i++) {
		scanf("%d%d", &num[i], &score[i]);
		sum = sum + score[i];
	}
	for (i = 0; i < N - 1; i++)
		for (j = i + 1; j < N; j++)
			if (score[j] > score[i]) {
				t = score[j]; score[j] = score[i]; score[i] = t;
				m = num[j]; num[j] = num[i]; num[i] = m;
			}
	printf("排序:\n");
	for (i = 0; i < N; i++)
		printf("%d\t%d\n", num[i], score[i]);
	printf("\n");
	average = sum / N;
	printf("超过均分:\n");
	for (i = 0; i < N; i++)
		if (score[i] > average)
			printf("%d\t%d \n", num[i], score[i]);
	//学生分数大于90分优秀,大于80分良好,大于70分中等,大于60分及格,小于60分不及格
	for (i = 0; i < N; i++) {
		if (score[i] >=60) {
			if (score[i] >= 90) you++;
			else if (score[i] >= 80) liang++;
			else if (score[i] >=70) zhong++;
			else jige++;
		}
		else buji++;
	}
	printf("\n优秀:%d个\n良好:%d个\n中等:%d个\n及格:%d个\n不及格:%d个\n", you, liang, zhong, jige, buji);
	//输入一个学号,输出该学号对应的学生信息
	printf("输入学生学号:");
	scanf("%d", &number);
	for (i = 0; i < N; i++)
		if (number == num[i]) printf("%d\t%d", num[i], score[i]);
	return 0;
}




你可能感兴趣的:(C语言练习之循环小题目)