| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 569 人关注过本帖
标题:做的不好
只看楼主 加入收藏
see235959850
Rank: 2
等 级:论坛游民
帖 子:380
专家分:29
注 册:2016-12-21
结帖率:100%
收藏
 问题点数:0 回复次数:1 
做的不好
程序代码:
#include<stdio.h>
void input(char(*p_course)[10], int *p_num, float *p_score)
{
    int i, j;
    printf("Please input student's number:\n");
    for (i = 0; i < 4; i++)
        scanf_s("%d", p_num + i);
    printf("Please input student's course:\n");
    for (j = 0; j < 5; j++)
        scanf_s("%s", p_course[j], 10);
    printf("Please input student's score:\n");
    for (i = 0; i < 4; i++)
        for (j = 0; j < 5; j++)
            scanf_s("%f", p_score + 5 * i + j);
}

void aver_score(float *p_score, float *p_aver)
{
    int i, j;
    float sum, aver;
    for (i = 0; i < 4; i++)
    {
        sum = 0;
        aver = 0;
        for (j = 0; j < 5; j++)
            sum += *(p_score + 5 * i + j);
        aver = sum / 5;
        *(p_aver + i) = aver;
    }
}

void aver_course(char(*p_course)[10], float *p_score)
{
    int i;
    float sum = 0, aver;
    for (i = 0; i < 4; i++)
        sum += *(p_score + 5 * i);
    aver = sum / 4;
    printf("course 1:%s average score is %5.2f\n", *p_course, aver);
}

void fail_score(char(*p_course)[10], int *p_num, float *p_score, float *p_aver)
{
    int i, j, k;
    printf("    ==============Student who is failed in two courses=============    \n");
    printf("No. ");
    for (i = 0; i < 5; i++)
        printf("%11s", p_course[i]);
    printf("       average\n");
    for (i = 0; i < 4; i++)
    {
        k = 0;
        for (j = 0; j < 5; j++)
            if (*(p_score + 5 * i + j) < 60)
                k++;
        if (k >= 2)
        {
            printf("%d", p_num[i]);
            for (j = 0; j < 5; j++)
                printf("%11.2f", *(p_score + 5 * i + j));
            printf("%11.2f\n", p_aver[i]);
        }
    }
}

void good_score(char(*p_course)[10], int *p_num, float *p_score, float *p_aver)
{
    int i, j, n;
    printf("      ===============Student whose score is good============    \n");
    printf("No. ");
    for (i = 0; i < 5; i++)
        printf("%11s", p_course[i]);
    printf("          average\n");
    for (i = 0; i < 4; i++)
    {
        n = 0;
        for (j = 0; j < 5; j++)
            if (*(p_score + 5 * i + j) > 85)
                n++;
        if (n == 5 || p_aver[i] > 90)
        {
            printf("%d", p_num[i]);
            for (j = 0; j < 5; j++)
                printf("%11.2f", *(p_score + 5 * i + j));
            printf("%11.2f\n", p_aver[i]);
        }
    }
}

int main()
{
    void input(char(*p_course)[10], int *p_num, float *p_score);
    void aver_score(float *p_score, float *p_aver);
    void aver_course(char(*p_course)[10], float *p_score);
    void fail_score(char(*p_course)[10], int *p_num, float *p_score, float *p_aver);
    void good_score(char(*p_course)[10], int *p_num, float *p_score, float *p_aver);
    char course[5][10], (*p_course)[10];
    int num[4], *p_num;
    float score[4][5], *p_score, aver[4], *p_aver;
    p_course = course;
    p_num = num;
    p_score = *score;
    p_aver = aver;
    input(p_course, p_num, p_score);
    aver_score(p_score, p_aver);
    aver_course(p_course, p_score);
    fail_score(p_course, p_num, p_score, p_aver);
    good_score(p_course, p_num, p_score, p_aver);
    return 0;
}

2017-01-27 22:13
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:0 
表示无语~感觉应该可以优化~

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2017-01-27 22:17
快速回复:做的不好
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.263936 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved