求两个班级的平均成绩


#include <stdio.h>
#define A 35
#define B 30

int main()
{
	float average(float array[], int n);
	float score1[35], score2[30]; //定义两个数组分别用来存放两个班级的学生成绩
	int i;
	printf("Please  star enter Class A %d studens score:\n",A);
	for (i = 0;i < A;i++)
	{
		printf("Please enter Class A the %d studens score:\n", i + 1);
		scanf("%f", &score1[i]);
		if (score1[i] < 0 || score1[i]>100)
		{
			printf("Input Error, Please reenter %d student:\n ", i + 1);
			i--;
		}
	}

	printf("\n\nPlease start Class B %d studens score:\n",B);


	for (i = 0;i < B;i++)
	{

		printf("Please enter Class B  the %d studens score:\n", i + 1);
		scanf("%f", &score2[i]);
		if (score2[i] < 0 || score2[i]>100)
		{
			printf("Please enter Class B the %d studens score:\n", i + 1);
			i--;
		}

	}

	printf("The average of class A is %6.2f\n", average(score1, A));
	printf("The average of class B is %6.2f\n", average(score2, B));
	return 0;
}

float average(float array[], int n) 
{
	int i;
	float aver, sum = array[0];
	for (i = 1;i < n;i++)
		sum = sum + array[i];	    
	aver = sum / n;
	return(aver);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值