作业
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student
{char name[32];int age;double score;
}s[3];void stu_input(struct student *s,int n)
{printf("请输入%d个学生的信息(姓名,年龄,成绩):\n",n);for (int i=0;i<n;i++){scanf("%s %d %lf",s[i].name,&s[i].age,&s[i].score);}
}void show_stu(struct student *s,int n)
{printf("%d位学生信息如下:\n",n);for (int i=0;i<n;i++){printf("姓名:%s 年龄:%d 成绩:%.2f\n",s[i].name,s[i].age,s[i].score);}
}void stu_del(struct student *s,int m,int pos)
{if(pos<0 || pos>=m){printf("输入出错\n");}else{for(int i=pos;i<m;i++){s[i-1]=s[i];}m--;printf("删除第%d位学生信息后:\n",pos);show_stu(s,m);}
}void stu_modify(struct student *s,int m,int pos)
{if(pos<0 || pos>=m){printf("输入出错\n");}else{printf("修改第%d位学生:\n",pos);printf("修改学生姓名为:");char stu_name[32];scanf("%s",stu_name);strcpy(s[pos-1].name,stu_name);printf("修改学生年龄为:");scanf("%d",&s[pos-1].age);printf("修改学生成绩为:");scanf("%lf",&s[pos-1].score);printf("修改第%d位学生信息后:\n",pos);show_stu(s,m);}
}void find_stu(struct student *s,int m,int pos)
{if(pos<0 || pos>=m){printf("输入出错\n");}else{printf("查找的第%d位学生信息如下:\n",pos);printf("姓名:%s 年龄:%d 成绩:%.2f\n",s[pos-1].name,s[pos-1].age,s[pos-1].score);}
}
int main(int argc, const char *argv[])
{int n=4;stu_input(s,n);show_stu(s,n);stu_del(s,n,2);stu_modify(s,n-1,2);find_stu(s,n-1,2);return 0;
}