• 抄写作业1


    #include<stdio.h>
    int main()
    {
    struct Student
    {
    long int num;
    char name[20];
    char sex;
    char addr[20];
     }
     a={10101,"lilin",'M',"123 Bei Jing Road"};
     printf("num=%d
    ,name=%s
    ,sex=%c
    ,addr=%s
    ",a.num,a.name,a.sex,a.addr);
     return 0;
    }
    复制代码
    运行结果
    
    num=10101 ,name=lilin ,sex=M ,addr=123 Bei Jing Road
    
    -------------------------------- Process exited after 0.2219 seconds with return value 0 请按任意键继续. . .
    
     
    
    9.2
    
    复制代码
    #include<stdio.h>
    int main()
    {
        struct Student
        {
            int num;
            char name[20];
            float score;
        }
        student1,student2;
        scanf("%d,%s,%f",&student1.num,&student1.name,&student1.score);
        scanf("%d,%s,%f",&student2.num,&student2.name,&student2.score);
        printf("The higher score is:
    ");
        if(student1.score>student2.score)
        printf("%d,%s,%f
    ",student1.num,student1.name,student1.score);
        else
         if(student1.score<student2.score)
        printf("%d,%s,%f
    ",student2.num,student2.name,student2.score);
        else
        {
            printf("%d,%s,%f
    ",student1.num,student1.name,student1.score);
            printf("%d,%s,%f
    ",student2.num,student2.name,student2.score);
        }
        return 0;
    }
    复制代码
    -------------------------------- Process exited after 0.2435 seconds with return value 0 请按任意键继续. . .
    
     
    
    9.3
    
    复制代码
    #include<string.h>
    #include<stdio.h>
    struct Person
    {
        char name[20];
        int count;
    }
    leader[3]={{"LI",0},{"zhang,0"},{"sun",0}};
    int main()
    {
        int i,j;
        char leader_name[20];
        for(i=1;i<=10;i++)
        {
            scanf("%s",leader_name);
            for(j=0;j<3;j++)
            if(strcmp(leader_name,leader[j].name)==0) leader[j].count++;
        }
        printf("
    Result:
    ");
        for(i=0;i<3;i++)
        printf("%5s,%d
    ",leader[i].name,leader[i].count);
        return 0;
    }
    复制代码
    -------------------------------- Process exited after 0.3419 seconds with return value 0 请按任意键继续. . .
    
    9.4
    
    复制代码
    #include<stdio.h>
    struct student
    {
        int num;
        char name[20];
        float score;
    };
    int main()
    {
        struct student stu[5]={{10101,"lili",78},{10103,"gygy",98.5},{10106,"fttf",86},{10108,"bbhh",73},{10110,"huhu",100}};
        struct student temp;
        int n=5;
        int i,j,k;
        printf("the order is:
    ");
        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("%d
    ,%s
    ,%f
    ",stu[i].num,stu[i].name,stu[i].score);
        return 0;
    }
    复制代码
    the order is: 10110 ,huhu ,100.000000 10103 ,gygy ,98.500000 10106 ,fttf ,86.000000 10101 ,lili ,78.000000 10108 ,bbhh ,73.000000
    
    -------------------------------- Process exited after 0.203 seconds with return value 0 请按任意键继续. . .
    
     
    
    9.5
    
    复制代码
    #include<stdio.h>
    #include<string.h>
    int main()
    {struct student
         long num;
         char name[20];
         char sex;
         float score;
    };
    struct student stu_1={10101,"Li Lin",'M',89.5};
    struct student *p;
    p=&stu_1;
    printf("%d
    ,%s
    ,%c
    ",stu_1.num,,stu_1.name,stu_1.sex,stu_1.score);
    printf("%d
    ,%s
    ,%c
    ",stu_1.num,,stu_1.name,stu_1.sex,stu_1.score);
    return 0;
    }
    复制代码
    -------------------------------- Process exited after 0.187 seconds with return value 0 请按任意键继续. . .
    
     
    
    9.6
    
    复制代码
    #include<stdio.h>
    struct student
    {
        int num;
        char name[20];
        char sex;
        int age;
    };
    int main()
    {
        struct student stu[3]={{10101,"lili",78},{10103,"gygy",98.5},{10106,"fttf",86}};
        int main()
        {struct student *p;
        printf("No.  Name     sex age
    ");
        for(p=stu;p<stu+3;p++)
        printf("%d
    ,%s
    ,%c
    ,%d
    ",p->num,p->name,p->sex,p->age);
        return 0;
    }
    }
    复制代码
    -------------------------------- Process exited after 0.1857 seconds with return value 0 请按任意键继续. . .
    
     
    
    9.7
    
    复制代码
    #include <stdio.h>  
    #define N 3  
    struct Student  
    {  
        int num;  
        char name[20];  
        float score[3];  
        float aver;  
    };  
    int main()
    {
        void input(struct Student stu[]);
        struct Student max(struct Student stu[]);
        void print(struct Student stu);
        struct Student stu[N],*p=stu;
        input(p);
        print(max(p));
        return 0; 
    }
    void input(struct Student stu[])
    {
        int i;
        printf("请输入各学生的信息:学号、姓名、三门学科的成绩:
    ");
        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("
    成绩最高的学生是:
    ");
        printf("学号:%d
    姓名:%s
    三门课成绩:%5.1f,%5.1f,%5.1f平均成绩:%6.2f
    ",stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2]);
    }
  • 相关阅读:
    阿里云 NAS OSS 云盘价格对比 GB/小时
    kubernetes/k8s pod下多容器的设计模式(ambassador 大使代理模式,adapter 适配模式,sidecar 边车模式, init containers初始化容器)
    ❤️ 从125ms到11ms,记一次关键字检测过滤服务的优化 -python and Pythonnet
    高效的的关键字查找和检测(哈希表和Trie前缀树和FastCheck)在实际使用中的性能
    FastAPI 中的Async (并发和async/await)
    阿里云vs华为云 的容器镜像服务swr使用体验
    Supermap IClient3D 加载3DTiles倾斜摄影数据
    C#根据数据生成力引导图
    Android WebView
    Nginx 反向代理地址后,session丢失,不能登录的问题
  • 原文地址:https://www.cnblogs.com/zxg99/p/6689318.html
Copyright © 2020-2023  润新知