首页 > 其他分享 >实验六

实验六

时间:2023-05-31 21:11:25浏览次数:30  
标签:Minn level int sum ++ STU 实验

task4

实验代码

#include <stdio.h>
#include <string.h>

#define N 100

typedef struct {
    char num[10];
    int s1, s2;
    double sum;
    char level[10];
} STU;

int fun(STU a[], int n, STU h[]);

int main() {
    STU s[N]={ {"GA05", 85, 76},
                {"GA03", 76, 90},
                {"GA02", 69, 90},
                {"GA04", 85, 56},
                {"GA01", 91, 95},
                {"GA07", 72, 80},
                {"GA08", 64, 45},
                {"GA06", 87, 98},
                {"GA015", 85, 86},
                {"GA013", 91, 97} }; 
    STU h[N];
    int i, k, n = 10;
    
    k = fun(s, n, h);
    
    printf("There are :\n");
    for(i = 0;i < k; i++) {
        printf("%s %d %d %.2f %s\n", h[i].num, h[i].s1, h[i].s2, h[i].sum, h[i].level);
    } 
    
    return 0;
        
}


int fun(STU a[], int n, STU h[]) {
    int i, t = 0;
    double sum = 0;
    
    for(i = 0;i < n; i++) {
        a[i].sum += 0.3 * a[i].s2 + 0.7 * a[i].s1;
        sum += a[i].sum;
    }
    sum /= n;
    
    for(i = 0;i < n; i++) 
        if(a[i].sum > sum) {
            h[t] = a[i];
            strcpy(h[t].level, "均分以上");
            t ++;
        }
        
    return t;
     
}

 

结果

task5

代码

#include <stdio.h>
#include <string.h>
#define N 5

typedef struct student {
    char name[10];
    int num;
    int maths;
    int computer;
    int english;
    int sum;
    char level[10];
} STU;

void fun(STU a[], int n);

int main() {
    
    STU s[6 * N]={ {"A001", 1, 34, 67, 80},
                    {"B003", 3, 78, 87, 90},
                    {"A002", 2, 90, 98, 99},
                    {"B002", 4, 56, 78, 98},
                    {"A005", 5, 35, 67, 79} };
    int i;
    
    fun(s, N);
    for(i = 0; i < N; i++)
        printf("%s %d %d %d %d %d %s\n", s[i].name, s[i].num, s[i].maths,s[i].computer, s[i].english, s[i].sum, s[i].level);
    
    return 0;
}

void fun(STU a[], int n) {
    int i, Maxn = 0, Minn = 1e9;
    
    for(i = 0;i < n; i++) {
        a[i].sum = a[i].maths + a[i].computer + a[i].english;
        if(a[i].sum > Maxn) Maxn = a[i].sum;
        if(a[i].sum < Minn) Minn = a[i].sum;
    }
    
    for(i = 0;i < n; i++) {
        if(a[i].sum == Maxn) strcpy(a[i].level, "优秀");
        else if(a[i].sum == Minn) strcpy(a[i].level, "不及格");
        else strcpy(a[i].level, "合格");
    }
    
}

 

结果

task6

代码

#include <stdio.h>
#define N 5

typedef struct student {
    long no;
    char name[20];
    int score;
} STU;

void input(STU s[], int n);
int find_min_list(STU s[], STU t[], int n);
void output(STU s[], int n);

int main() {
    STU stu[N], min_list[N];
    int count;
    
    printf("录入%d个学生信息\n", N);
    input(stu, N);
    printf("\n统计最低分人数和学生信息...\n");
    count = find_min_list(stu, min_list, N);
    printf("\n一共有%d个最低分,信息如下:\n", count);
    output(min_list, count);
    
    return 0;
}

void input(STU s[], int n) {
    int i;
    
    for(i = 0;i < n; i++) 
        scanf("%ld %s %d", &s[i].no, &s[i].name, &s[i].score);

}

void output(STU s[], int n) {
    int i;
    
    for(i = 0;i < n; i++) 
        printf("%ld %s %d\n", s[i].no, s[i].name, s[i].score);
}

int find_min_list(STU s[], STU t[], int n) {
    int i, m = 0, Minn = 1e9;
    
    for(i = 0;i < n; i++)
        if(s[i].score < Minn) Minn = s[i].score;
        
    for(i = 0;i < n; i++)
        if(s[i].score == Minn) t[m ++] = s[i];
    
    return m;

}

/*
1001 钢铁侠 98
1002 蜘蛛侠 96
1003 绿巨人 90
1004 黑寡妇 91
1005 黄蜂女 92
*/

 

结果

 

标签:Minn,level,int,sum,++,STU,实验
From: https://www.cnblogs.com/jw321/p/17447340.html

相关文章

  • 实验6
    task4.c代码:#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];ints1;ints2;doublesum;charlevel[10];}STU;intfun(STUa[],intn,STUh[]);intmain(){STUs[N]={{"GA05&quo......
  • 实验6
    task4#include<stdio.h>#include<stdlib.h>#include<string.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时成绩doublesum;//总评charlevel[10];......
  • 实验6
    task4编程代码#include<stdio.h>#include<stdlib.h>#include<string.h>#defineN100typedefstruct{charnum[10];ints1;ints2;doublesum;charlevel[10];}STU;intfun(STUa[],intn,STUh[]);intmain(){......
  • 实验六
    实验六实验任务4实验代码#include<stdio.h>#include<string.h>#defineN100typedefstruct{ charnum[10]; ints1,s2; doublesum; charlevel[10];}STU;intfun(STUa[],intn,STUh[]);intmain(){ STUs[N]={{"GA05",85,76}, ......
  • 实验6
    实验任务4#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时成绩doublesum;//总评charlevel[10];//等级}STU;......
  • 实验六
    //任务一//P286例8.17//对教材上的程序作了微调整,把输出学生信息单独编写成一个函数模块//打印不及格学生信息和所有学生信息程分别调用#include<stdio.h>#include<string.h>#defineN3//运行程序输入测试时,可以把这个数组改小一些输入测试typedefst......
  • 实验6
    task4.c#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];ints1;ints2;doublesum;charlevel[10];}STU;intfun(STUa[],intn,STU......
  • 实验6
    实验任务4程序源代码#include<stdio.h>#include<string.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];ints1;ints2;doublesum;charlevel[10];}STU;intfun(STUa[],intn,STUh[]);intmain(){......
  • 【2023 · CANN训练营第一季】——Ascend C算子沙箱实验
    前言:CANN训练营的Ascend C算子课程,以在线课程的方式提供了一个沙箱实验环境。这将有助于帮助开发者了解Ascend C算子开发的软、硬件环境;熟悉自定义AscendC算子的开发流程和关键代码;同时也可以了解到自定义算子包的部署路径及部署后的各类文件。在线试验地址:在线实验>基于昇腾CA......
  • 实验6
    任务4:实验源码:#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];ints1;ints2;doublesum;charlevel[10];}STU;intfun(STUa[],intn,......