抄写例题

Posted 丁玉彬

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了抄写例题相关的知识,希望对你有一定的参考价值。

#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 请按任意键继续. . .

 

以上是关于抄写例题的主要内容,如果未能解决你的问题,请参考以下文章

抄写例题作业1

抄写例题作业

抄写例题作业:

抄写例题作业1

抄写例题

抄写例题作业