| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2161 人关注过本帖
标题:输入10名学生5门课程的成绩,分别用函数实现下列功能
只看楼主 加入收藏
壹墨
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-11-25
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
输入10名学生5门课程的成绩,分别用函数实现下列功能
1、计算每个学生的平均分
2、计算每门课的平均分
3、找出所有50个分数中最高的分数所对应的学生和课程
4、按每个学生的平均分,对所有的成绩按由高到低的顺序排序
搜索更多相关主题的帖子: 课程 
2016-12-06 15:50
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10551
专家分:42996
注 册:2014-5-20
收藏
得分:10 
就是在电脑屏上画出一张成绩表
也可先在纸上画画算算
2016-12-08 07:51
imzaghi333
Rank: 2
来 自:江苏昆山
等 级:论坛游民
帖 子:34
专家分:61
注 册:2013-9-7
收藏
得分:10 
给你找个例子,模仿一下。

#include <stdio.h>
#define SIZE 100

void mean(const int answer[]);
void median(int answer[]);
void mode(int freq[], const int answer[]);
void bubbleSort(int answer[]);
void printArray(const int answer[]);

int main(void)
{
    int response[ SIZE ] = { 6, 7, 8, 9, 8, 7, 8, 9, 8, 9,
                            7, 8, 9, 5, 9, 8, 7, 8, 7, 1,
                            6, 7, 8, 9, 3, 9, 8, 7, 1, 7,
                            7, 8, 9, 8, 9, 8, 9, 7, 1, 9,
                            6, 7, 8, 7, 8, 7, 9, 8, 9, 2,
                            7, 8, 9, 8, 9, 8, 9, 7, 5, 3,
                            5, 6, 7, 2, 5, 3, 9, 4, 6, 4,
                            7, 8, 9, 6, 8, 7, 8, 9, 7, 1,
                            7, 4, 4, 2, 5, 3, 8, 7, 5, 6,
                            4, 5, 6, 1, 6, 5, 7, 8, 7, 9};
    int frequency[10] = {0};
    mean(response);
    median(response);
    mode(frequency, response);
    return 0;
}
void mean(const int answer[])
{
    int counter;
    int total = 0;
    printf( "%s\n%s\n%s\n", "**********", "*  Mean  *", "**********" );
    for(counter = 0; counter < SIZE; counter++){
        total += answer[counter];
    }
    printf( "Mean is the average value of all datas\n" );
    printf( "Mean value for this run is: " );
    printf("%d / %d = %.2lf\n\n", total, SIZE, (double)total/SIZE);
}
void median(int answer[])
{
    printf( "\n%s\n%s\n%s\n", "*************", "*  Median  *", "*************" );
    printf("Unsortted array of response: \n");
    printArray(answer);
    printf("\n");
    printf("\nSorted array of response: \n");
    bubbleSort(answer);
    printArray(answer);
    printf("\n\n");
    if(SIZE%2 == 0){
        printf("Median is average of elements %d and %d\n", SIZE/2, SIZE/2+1);
        printf("in the sorted %d element array.\n", SIZE);
        printf( "For this run median: %.2lf\n", (double)(answer[SIZE/2]+answer[SIZE/2+1])/2);
    }
    else{
        printf("Media is average of elements %d" , (SIZE+1)/2);
        printf("in the sorted %d element array.\n", SIZE);
        printf( "For this run median: %d", answer[(SIZE+1)/2]);
    }
}
void mode(int freq[], const int answer[])
{
    int rate;   //count for elements 1~~9
    int loop;     //count for all elements 0~SIZE
    int largest = 0;  //largest frequency
    int counter = 0;  //flag to count number of modes
    int modeValue[10] = {0};   //most frequency response

    printf("\n%s\n%s\n%s\n", "**********", "*  Mode  *", "**********");

    for(rate = 1; rate <= 9; rate++){
        freq[rate] = 0;
    }    // inti frequencies as 0

    for(loop = 0; loop < SIZE; loop++){
        ++freq[answer[loop]];
    }    //traverse array and increment corresponding frequency

    printf("%s%11s%13s\n\n", "Response", "Frequency", "Histogram");
    for(rate = 1; rate <=9 ;rate++){
        printf("%3d%10d           ", rate, freq[rate]);
        if(freq[rate]>largest){
            largest = freq[rate];
            for(loop = 0; loop < 10; loop++){
                modeValue[loop] = 0;
            }
            modeValue[rate] = largest;
            ++counter;
        }
        else if(freq[rate] == largest){
            modeValue[rate] = largest;
            ++counter;
        }
        for(loop = 1; loop <= freq[rate]; loop++){
            printf("*");
        }
        printf("\n");
    }
    printf("\n");
    if(counter > 1){
        printf("Modes are: ");
    }
    else{
        printf("Mode is: ");
    }
    for(loop = 1; loop <= 9; loop++){
        if(modeValue[loop] != 0){
            printf("%d with a frequency of %d\n\t\t", loop, modeValue[loop]);
        }
    }
    printf("\n");
}
void bubbleSort(int answer[])
{
    int loop;
    int i;
    int tmp;
    for(loop = 0; loop < SIZE; loop++){
        for(i = 0; i < SIZE-i; i++){
            if(answer[i]>answer[i+1]){
                tmp = answer[i];
                answer[i] = answer[i+1];
                answer[i+1] = tmp;
            }
        }
    }
}
void printArray(const int answer[])
{
    int loop;
    for(loop = 0; loop < SIZE; loop++){
        if(loop%20 == 0){
            printf("\n");
        }
        printf("%2d", answer[loop]);
    }
}

非专业的C语言爱好者.正在学习中..........
2016-12-08 21:09
快速回复:输入10名学生5门课程的成绩,分别用函数实现下列功能
数据加载中...
 
   



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

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