0
点赞
收藏
分享

微信扫一扫

C++之数组使用实例

静守幸福 2022-01-27 阅读 40

1.字符组与字符串:
字符数组+空字符(\0),

2.用for循环中使用数组

#include <stdio.h>

#define SIZE 10
#define PAR 72

int main(void)
{
	int index,score[SIZE];
	int sum=0;
	float average;

	printf("Enter %d golf scores:\n",SIZE);
	for (index=0;index<SIZE;index++)
		scanf("%d",&score[index]);
	printf("The scores read in are as follow:\n");
	for(index=0;index<SIZE;index++)
		printf("%5d",score[index]);
	printf("\n");
	for(index=0;index<SIZE;index++)
		sum+=score[index];
	average=(float)sum/SIZE;
	printf("Sum of scores=%d0.f.\n",average - PAR);

	return 0;

}




3.结果
在这里插入图片描述

举报

相关推荐

0 条评论