c语言输入学生的三门成绩
时间: 2023-07-13 17:25:10 浏览: 91
好的,我可以帮你解答。你可以使用C语言中的scanf()函数实现输入学生的三门成绩。具体代码如下:
```c
#include <stdio.h>
int main() {
float score1, score2, score3;
printf("请输入学生的三门成绩:\n");
scanf("%f %f %f", &score1, &score2, &score3);
printf("学生的三门成绩分别为:%.2f %.2f %.2f\n", score1, score2, score3);
return 0;
}
```
在这个例子中,我们定义了三个变量来存储学生的三门成绩。使用printf()函数输出提示信息,让用户输入学生的三门成绩,并使用scanf()函数获取用户输入的数据。最后再用printf()函数输出学生的成绩。注意,%.2f表示输出浮点数时保留两位小数。
相关问题
c语言输入3名学生三门课
可以使用C语言编程实现输入三名学生的三门课成绩。
首先,我们需要定义一个结构体来存储学生的信息和成绩,如下所示:
```c
#include <stdio.h>
// 定义学生结构体
struct Student
{
char name[50]; // 学生姓名
float score1; // 第一门课成绩
float score2; // 第二门课成绩
float score3; // 第三门课成绩
};
```
接下来,我们可以在主函数中创建一个包含三个学生的数组,并使用循环来输入学生的姓名和成绩:
```c
int main()
{
struct Student students[3]; // 创建包含三个学生的数组
// 输入学生的姓名和成绩
for (int i = 0; i < 3; i++)
{
printf("请输入第%d名学生的姓名:", i + 1);
scanf("%s", students[i].name);
printf("请输入该学生的三门课成绩:");
scanf("%f%f%f", &students[i].score1, &students[i].score2, &students[i].score3);
}
return 0;
}
```
以上代码将实现输入三名学生的姓名和每门课成绩。你可以根据需要对学生信息进行处理和输出。
用c语言写三门成绩求两门以上不及格的学生
以下是用 C 语言编写的代码,用于计算三门成绩并找出两门以上不及格的学生:
```c
#include <stdio.h>
int main() {
int n, i, count;
float score1, score2, score3;
printf("请输入学生人数:");
scanf("%d", &n);
count = 0;
for (i = 1; i <= n; i++) {
printf("请输入第 %d 个学生的三门成绩:", i);
scanf("%f%f%f", &score1, &score2, &score3);
if (score1 < 60 && score2 < 60 && score3 < 60) {
continue;
}
if (score1 < 60 && score2 < 60) {
count++;
}
if (score1 < 60 && score3 < 60) {
count++;
}
if (score2 < 60 && score3 < 60) {
count++;
}
}
printf("两门以上不及格的学生人数为:%d\n", count);
return 0;
}
```
希望这个代码能够帮到你!