设计一个学生成绩管理系统,写出完整的c语言代码
时间: 2023-03-14 16:03:30 浏览: 98
#include<stdio.h>
int main()
{
int n, i;
float grades[100];
float total = 0.0;
printf("输入学生的数量: ");
scanf("%d", &n);
printf("输入 %d 个学生成绩\n", n);
for(i = 0; i < n; ++i)
{
printf("学生 %d: ", i+1);
scanf("%f", &grades[i]);
total += grades[i];
}
printf("\n总成绩 = %.2f\n", total);
printf("平均成绩 = %.2f\n", total/n);
return 0;
}
相关问题
请写出学生成绩管理系统的c语言代码
以下是一个简单的学生成绩管理系统的 C 语言代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
typedef struct {
char name[50];
int id;
float grade;
} Student;
void add_student(Student students[], int *num_students) {
if (*num_students >= MAX_STUDENTS) {
printf("Error: Maximum number of students reached.\n");
return;
}
Student s;
printf("Enter name: ");
scanf("%s", s.name);
printf("Enter ID: ");
scanf("%d", &s.id);
printf("Enter grade: ");
scanf("%f", &s.grade);
students[*num_students] = s;
(*num_students)++;
printf("Student added successfully.\n");
}
void remove_student(Student students[], int *num_students) {
int id;
printf("Enter ID of student to remove: ");
scanf("%d", &id);
for (int i = 0; i < *num_students; i++) {
if (students[i].id == id) {
for (int j = i; j < *num_students - 1; j++) {
students[j] = students[j + 1];
}
(*num_students)--;
printf("Student removed successfully.\n");
return;
}
}
printf("Error: Student with ID %d not found.\n", id);
}
void print_students(Student students[], int num_students) {
printf("Name\tID\tGrade\n");
for (int i = 0; i < num_students; i++) {
printf("%s\t%d\t%.2f\n", students[i].name, students[i].id, students[i].grade);
}
}
int main() {
Student students[MAX_STUDENTS];
int num_students = 0;
int choice;
while (1) {
printf("\nStudent Grade Management System\n");
printf("1. Add Student\n");
printf("2. Remove Student\n");
printf("3. Print Students\n");
printf("4. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student(students, &num_students);
break;
case 2:
remove_student(students, &num_students);
break;
case 3:
print_students(students, num_students);
break;
case 4:
printf("Exiting program.\n");
exit(0);
default:
printf("Invalid choice.\n");
}
}
return 0;
}
```
该代码中定义了一个 `Student` 结构体,该结构体包含学生的姓名、ID 和成绩。然后,定义了三个函数来实现添加学生、删除学生和打印学生列表的功能。最后,在 `main()` 函数中实现了一个简单的菜单,让用户可以选择要执行的操作。
C语言写出学生成绩管理系统代码
我可以回答这个问题,以下是一个简单的C语言学生成绩管理系统代码:
#include <stdio.h>
struct student {
char name[50];
int roll;
float marks;
} s;
int main() {
printf("Enter information of students:\n\n");
printf("Enter name: ");
scanf("%s", s.name);
printf("Enter roll number: ");
scanf("%d", &s.roll);
printf("Enter marks: ");
scanf("%f", &s.marks);
printf("\nDisplaying Information:\n\n");
printf("Name: %s\n", s.name);
printf("Roll number: %d\n", s.roll);
printf("Marks: %.2f\n", s.marks);
return 0;
}
阅读全文