当前位置:首页 » 编程语言 » c语言统计五人成绩
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言统计五人成绩

发布时间: 2023-01-07 05:27:17

① 输入5个同学的成绩求出平均成绩,并输出不及格人数和成绩,要求用数组。c语言

#include<stdio.h>
intmain()
{
inta[5];
doublesum=0;
intj=0;
for(inti=0;i<5;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
if(a[i]<60)j++;
}
printf("平均分:%.2lf ",sum);
printf("不合格人数:%d ",j);
for(inti=0;i<5;i++)
{
if(a[i]<60)printf("%d ",a[i]);
}
}

② c语言 定义数组,使用循环输入五名学生的成绩,并输出所有学生的成绩信息

#include<stdio.h>

typedefstruct{
charname[1024];
intscore;
}Student;

intmain(){
inti;
Studentstudents[]={{"张三",90},{"李四",88},{"王五",99},{"赵四",66},{"齐秦",59}};
printf("学生的信息如下: ");
for(i=0;i<5;i++){
printf("%s%d ",students[i].name,students[i].score);
}
return0;
}

③ C语言编程用数组输入5个学生的成绩求出这些学生的平均成绩,并输出所有高出平均值的成绩

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

namespace_118_3._4

classProgram

staticvoidMain(string[]args)

int[]a=newint[5]{78,90,86,75,92};

doubles=0;

for(inti=0;i<a.Length;i++)

if(a[0]<a[i])a[0]=a[i];

s+=a[i];

Console.WriteLine("最高成绩为;{0}",a[0]);

Console.WriteLine("平均成绩为;{0}",s/a.Length);

运行效果:

(3)c语言统计五人成绩扩展阅读

while语句若一直满足条件,则会不断的重复下去。但有时,需要停止循环,则可以用下面的三种方式:

一、在while语句中设定条件语句,条件不满足,则循环自动停止。

如:只输出3的倍数的循环;可以设置范围为:0到20。

二、在循环结构中加入流程控制语句,可以使用户退出循环。

1、break流程控制:强制中断该运行区内的语句,跳出该运行区,继续运行区域外的语句。

2、continue流程控制:也是中断循环内的运行操作,并且从头开始运行。