
1.10位改成了3位。
#include"stdio.h"
#define N 3
struct student
{
char StuID[15];
char Name[10];
float Grade[3];
}stu[N];
int main()
{
int i=0, j;
for (i=0; i < N; i++)
{
printf("请输入第%d位学生的ID、名字:n",i+1);
scanf("%s %s", &stu[i].StuID, &stu[i].Name);
printf("请输入第%d位学生三门课的成绩:n",i+1);
for (j = 0; j < 3; j++)
{
scanf("%f", &stu[i].Grade[j]);
}
}
for (i = 0; i < N; i++)
{
float sum=0;
printf("%s %sn", stu[i].StuID, stu[i].Name);
for (j = 0; j < 3; j++)
{
sum = sum + stu[i].Grade[j];
}
printf("第%d位同学的平均分为:%fn",i+1,sum/3.0);
}
return 0;
}
#include//头文件 int main()//主函数 { int i,k,n,m;//定义整型变量 int num[50];//定义整型数组 int *p;//定义指针变量 printf("输入n=");//提示语句 scanf("%d",&n);//键盘输入 p=num; for(i=0;i
#include "stdio.h" #include "stdlib.h" #include "string.h" struct address_book { char birth[9]; char name[31]; char phone[18]; struct address_book *next; }; void creat_book(struct address_book *head,int n) { int i; struct address_book *q; q=head; for(i=0;i<=n;i++) { struct address_book *p; if((p=((struct address_book *)malloc(sizeof(struct address_book))))==NULL) { printf("Sorry 分配内存失败。。。n"); exit(0); } q->next=p; p->next=NULL; q=p; } } void input_book(struct address_book *head,int n) { int i; //double jpr; //char tname[31]; struct address_book *q; q=head->next; printf("录入 %d 组通讯录信息n(姓名 生日 电话)n",n); for(i=0;iname,&q->birth,&q->phone); q=q->next; } } void pout_book(struct address_book *head,int n) { int i,j; struct address_book *q ,*min_p,*mark_p; q=head->next; min_p=q; for(i=0;i birth,q->birth)>0) min_p=q; q=q->next; } mark_p=min_p;//标记最大年龄 //printf("%s %s %sn",mark_p->name,mark_p->birth,mark_p->phone); for(i=0;i next; min_p=q; printf("%s %s %sn",mark_p->name,mark_p->birth,mark_p->phone); for(j=0;j birth,mark_p->birth)>0&&strcmp(min_p->birth,q->birth)>0) min_p=q;//重新标记 q=q->next;//向下比较 } mark_p=min_p;//标记最大年龄节点 } printf("nn"); } int main() { printf("******通讯录排序******nn"); struct address_book *head;//定义头结点,指定书籍目录入口 if((head=(struct address_book *)malloc(sizeof(struct address_book)))==NULL) { printf("Sorry 分配内存失败......n"); exit(0); } int n; printf("要排序的通讯录数量: "); scanf("%d",&n);//指定录入通讯录的数量 creat_book(head,n);//按需创建指定数量的链表 input_book(head,n); //录入信息 printf("nn"); //区分输出 pout_book(head,n);//排序并输出信息 system("pause"); } 欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)