用c编写一个体测成绩系统
下面是一个用C语言编写的体测成绩系统的示例代码:
#include <stdio.h>
struct Student {
char name[50];
float height;
float weight;
};
void inputStudent(struct Student *student) {
printf("请输入学生姓名: ");
scanf("%s", student->name);
printf("请输入学生身高(cm): ");
scanf("%f", &(student->height));
printf("请输入学生体重(kg): ");
scanf("%f", &(student->weight));
}
void outputStudent(struct Student student) {
printf("学生姓名: %s\n", student.name);
printf("学生身高: %.2f cm\n", student.height);
printf("学生体重: %.2f kg\n", student.weight);
}
float calculateBMI(struct Student student) {
float heightMeter = student.height / 100;
return student.weight / (heightMeter * heightMeter);
}
int main() {
struct Student student;
inputStudent(&student);
printf("\n");
outputStudent(student);
printf("学生BMI指数: %.2f\n", calculateBMI(student));
return 0;
}
这个程序通过一个Student
结构体来存储学生的信息,包括姓名、身高和体重。inputStudent
函数用于输入学生的信息,outputStudent
函数用于输出学生的信息,calculateBMI
函数用于计算学生的BMI指数。在main
函数中,首先调用inputStudent
函数输入学生信息,然后调用outputStudent
函数输出学生信息,并调用calculateBMI
函数计算学生的BMI指数
原文地址: https://cveoy.top/t/topic/ijHu 著作权归作者所有。请勿转载和采集!