作業
#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;
}