码迷,mamicode.com
首页 > 其他好文 > 详细

作业 4.9

时间:2017-04-09 23:29:08      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:include   put   ring   else   scanf   []   log   roc   clu   

#include<stdio.h>
struct Student
{
    long int num;
    char name[30];
    char sex;
    char addr[100];
    
};
int main()
{
    struct Student a={10101,"LiLin",M,"123 bei jing road"};
    printf("num:%d\nname:%s\nsex:%c\naddr:%s\n",a.num,a.name,a.sex,a.addr);
} 

1

结果:

num:10101 name:LiLin sex:M addr:123 bei jing road

-------------------------------- Process exited after 0.4208 seconds with return value 50 请按任意键继续. . .

#include<stdio.h>
struct stu
{
    int num;
    char name[30];
    float score;
};
int main()
{
    struct stu student1,student2;
    scanf("%d%s%f",&student1.num,student1.name,&student1.score);
    scanf("%d%s%f",&student2.num,student2.name,&student2.score);
    if(student1.score>student2.score)
    printf("%d  %s  %6.2f",student1.num,student1.name,student1.score);
    else if(student1.score<student2.score)
    printf("%d  %s %6.2f",student2.num,student2.name,student2.score);
    else
    {
    printf("%d  %s  %6.2f",student1.num,student1.name,student1.score);
    printf("%d  %s  %6.2f",student2.num,student2.name,student2.score);
    }
}

2

结果:

 

001 ke 77 002 fe 99 2  fe  99.00 -------------------------------- Process exited after 36.61 seconds with return value 12 请按任意键继续. . .

 

#include<string.h>
#include<stdio.h>
struct people
{
    char name[20];
    int count;
};
int main()
{
     struct people a[3]={{"zhao",0},{"li",0},{"sun",0}};
     int i,j;
     char b[40];
     for(i=0;i<=10;i++)
     {scanf("%s",b);
      for(j=0;j<3;j++)
      if(strcmp(b,a[j].name)==0)
         a[j].count++;
     }
      for(i=0;i<3;i++)
      {printf("%s,%d\n",a[i].name,a[i].count);} 
       return 0;
}
 

3,

结果:

zhao li li zhao sun sun zhao li li zhao zhao zhao,5 li,4 sun,2

-------------------------------- Process exited after 88.47 seconds with return value 0 请按任意键继续. . .

#include<stdio.h>
struct student
{
    int num;
    char name[20];
    float score;
};
int main()
{
   struct student Stu[5]={{10101,"Zhang",78},
                          {10103,"Wang",98.5},
                          {10106,"Li",86},
                          {10108,"Ling",73.5},
                          {10110,"Sun",100}};
    struct student temp;
    const int n=5;
    int i,j,k;
    printf("The order is:\n");
    for(i=0;i<n-1;i++)
    { k=i;
    for(j=i+1;j<n;j++)
    if(Stu[j].score>Stu[k].score)
             k=j;
    temp=Stu[k];Stu[k]=Stu[i];Stu[i]=temp;
    }
    for(i=0;i<n;i++)
    printf("%6d %8s %6.2f\n",Stu[i].num,Stu[i].name,Stu[i].score);
    printf("\n");
    return 0;
} 


4

结果:

The order is:  10110      Sun 100.00  10103     Wang  98.50  10106       Li  86.00  10101    Zhang  78.00  10108     Ling  73.50

-------------------------------- Process exited after 0.04819 seconds with return value 0 请按任意键继续. . .

#include<stdio.h>
#include<string.h>
struct Student
{
    long num;
    char name[20];
    char sex;
    float score;
};
int main()
{
    struct Student stu_1;
    struct Student   *p;
    p=&stu_1;
    stu_1.num=10101;
    strcpy(stu_1.name,"Li Lin");
    stu_1.sex=M;
    stu_1.score=89.5;
    printf("NO:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",
            stu_1.num,stu_1.name,stu_1.sex,stu_1.score);
    printf("\nNO:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",
           (*p).num,(*p).name,(*p).sex,(*p).score);
    return 0;
} 

5

结果:

NO:10101 name:Li Lin sex:M score: 89.5

NO:10101 name:Li Lin sex:M score: 89.5

-------------------------------- Process exited after 0.2318 seconds with return value 0 请按任意键继续. . .

 

#include<stdio.h>
struct student
{
    int num;
    char name[20];
    char sex;
    int age;
    
};
 struct student stu[3]={{10101,"LiLin",M,10},
                        {10102,"ZhangFang",M,19},
                        {10104,"Wang Min",F,20}};
int main()
{
    struct student *p;
    printf("No    Name                 sex age\n");
    for(p=stu;p<stu+3;p++)
    printf("%5d %-20s %2c %4d\n",p->num,p->name,p->sex,p->age);
    return 0;
}


6,

结果 :

 

No    Name                 sex age LiLin                 M   10 ZhangFang             M   19 Wang Min              F   20

-------------------------------- Process exited after 0.2395 seconds with return value 0 请按任意键继续. . .

 

#include<stdio.h>
#define N 3
struct Student
{  int num;
   char name[20];
   float score[3];
   float aver;
};
void input(struct Student stu[])
{
    int i;
    printf("请输入各学生信息、学号、姓名三门课成绩:\n");
    for(i=0;i<N;i++)
    {scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,
      &stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
      stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
    }
}
struct Student max(struct Student stu[])
{
    int i,m=0;
    for(i=0;i<N;i++)
        if(stu[i].aver>stu[m].aver) m=i;
         return stu[m];
}
void print(struct Student stud)
{
    printf("\n学生的最高成绩是:\n");
    printf("学号:%d\n姓名:%s\n三门课成绩:%5.1f,%5.1f,%5.1f\n平均成绩:%6.2f\n",
       stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2],stud.aver);
}
int main()
{
struct Student stu[N],*p=stu;
       input(p);
       print(max(p));
       return 0;     
}

7

结果:

请输入各学生信息、学号、姓名三门课成绩: 10101 linkang 85 72 63 10102 dert 62 74 83 10103 qwer 74 76 80

学生的最高成绩是: 学号:10103 姓名:qwer 三门课成绩: 74.0, 76.0, 80.0 平均成绩: 76.67

-------------------------------- Process exited after 71.00 seconds with return value 0 请按任意键继续. . .

 

作业 4.9

标签:include   put   ring   else   scanf   []   log   roc   clu   

原文地址:http://www.cnblogs.com/sunmingyang/p/6686887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!