⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lind8-14.c

📁 谭浩强第二版的课后习题的答案的源程序
💻 C
字号:
#include<stdio.h>

int a[10][6];
float ab[10],ac[10];
float f[10];
char o[5][10]={"Chinese \0","Math    \0","English \0","PE      \0","CProgram\0"};
int i,j,m=0,n=0,ma;
float q;

void input()
{
	printf("\nPlease input the\nstudents'number the marks of Chinese math English PE and C program\n\n");
	for(i=0;i<10;i++)
	for(j=0;j<6;j++)
	{
		if(j==0)
		printf("Please input the No.%d's marks.\n",i+1);
		scanf("%d",&a[i][j]);
	}
	printf("\n");
}

void aver()
{
	int u=0,t=0;
	for(i=0;i<=9;i++)
	for(j=1;j<=5;j++)
	{
		u=u+a[i][j];
		if(j==5)
		{
			ab[i]=u;
			u=0;
		}
	}

	for(j=1;j<=5;j++)
	for(i=0;i<10;i++)
	{
		t=t+a[i][j];
		if(i==9)
		{
			ac[j-1]=t;
			t=0;
		}
	}
}

void max()
{
	ma=0;
	for(i=0;i<10;i++)
	for(j=1;j<6;j++)
	{
		if(a[i][j]>ma)
		{
			ma=a[i][j];
			m=i;
			n=j;
		}
	}
}

void fangcha()
{
	long x1=0,x2=0,temp;
	for(i=0;i<10;i++)
	{
		x1=x1+ab[i];
		x2=x2+ab[i]*ab[i];
	}
	temp=x1*x1;
	q=x2/10-temp/100;
}

void output()
{
	printf("Students' averages:\nNumber     average\n");
	for(i=0;i<10;i++)
	{
		printf("%d          %.2f\n",i+1,ab[i]/5);
	}

	printf("\nObjects' averages:\nObjects      averge\n");
	for(i=0;i<5;i++)
	{
		printf("%s     %.2f \n",o[i],ac[i]/10);
	}

	printf("\nNo.%d's %s is the max mark of all.\n\n",m+1,o[n-1]);

	printf("\nThe variance is %.2f\n\n",q);

}

void main()
{
	input();
	aver();
	max();
	fangcha();
	output();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -