第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

平均分大了一倍那樣,希望大佬解答

#include <stdio.h>

int sum = 0.00;

int max;

int min;

double maen;

int i;

int j;

int summation(int score[])

{

? ? for(i = 0; i < 10; i++)

? ? {

? ? ? ? sum += score[i];

? ? }

? ? return sum;

}

int maximal(int score[])

{

? ? max = score[0];

? ? for(i = 0; i < 10; i++)

? ? {

? ? ? ? if(score[i] > max)

? ? ? ? {

? ? ? ? ? ? max = score[i];

? ? ? ? }

? ? }

? ? return max; ??

}

int minimum(int score[])

{

? ? min = score[0];

? ? for(i = 0; i<10; i++)

? ? {

? ? ? ? if(score[i] < min)

? ? ? ? {

? ? ? ? ? ? min = score[i];

? ? ? ? }

? ? }

? ? return min;

}

double average(int score[])

{

? ? double a = summation(score);

? ? maen = a / 10;

? ? return maen;

}

void descending_order(int score[])

{

? ? for(i = 0; i < 9; i++)

? ? {

? ? ? ? for(j = 0; j <= i; j++)

? ? ? ? {

? ? ? ? ? ? int n = 0;

? ? ? ? ? ? if(score[j] > score[j + 1])

? ? ? ? ? ? {

? ? ? ? ? ? ? ? n = score[j];

? ? ? ? ? ? ? ? score[j] = score[j + 1];

? ? ? ? ? ? ? ? score[j + 1] = n;

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? for(i = 0; i < 10; i++)

? ? {

? ? ? ? if(i < 9)

? ? ? ? {

? ? ? ? ? ? printf("%d, ", score[i]);

? ? ? ? }else{

? ? ? ? ? ? printf("%d", score[i]);

? ? ? ? }

? ? }

}


int main()

{

? ? int score[10]={67,98,75,63,82,79,81,91,66,84};

? ? printf("班級總分為:%d\n", summation(score));

? ? printf("班級的最高分為:%d\n", maximal(score));

? ? printf("班級的最低分為:%d\n", minimum(score));

? ? printf("班級的平均分為:%.2f\n", average(score));

? ? descending_order(score);

}


正在回答

1 回答

第一點我需要吐槽的是你的代碼沒有可讀性,很雜亂。第二我已經(jīng)看出來的你的問題了,全局變量和局部變量名重復(fù)了,導(dǎo)致改變了變量中的值。我建議你不要全局變量,只在函數(shù)中定義局部變量,當你需要哪些變量的時,在定義。這樣即使兩個局部變量名重復(fù)了也不影響變量中的值。


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
C語言入門
  • 參與學(xué)習(xí)       926892    人
  • 解答問題       21442    個

C語言入門視頻教程,帶你進入編程世界的必修課-C語言

進入課程

平均分大了一倍那樣,希望大佬解答

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號