課程
/后端開發(fā)
/C
/C語言入門
我想提個問題,replaceMax里面是arr[] 數(shù)組, 而主函數(shù)里面是arr1 和 arr2 。。。
2017-01-02
源自:C語言入門 6-4
正在回答
對的 ,只是arr[]是形參 ,而arr1[]與arr2[]是實參 ,其中 arr1[]輸出的是數(shù)組中全部內(nèi)容,而arr2只是輸出了第一個元素的內(nèi)容?
#include <stdio.h>
#define N 10
//打印分?jǐn)?shù)
void printScore(int score[])
{
? ? int i;
? ? printf("\n");
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? printf("%d",score[i]);
? ? }
}
//計算考試總分
int getTotalScore(int score[])
? ? int sum=0;
? ? inti;
? ? ? ? sum+=score[i];
? ? return sum;
//計算平均分
int AverangeScore(int score[])
? ? return getTotalScore/N;
//計算最高分
int getMax(int score[])
? ? int max=-1;
? ? ? ? if(score[i]>max)
? ? ? ? {
? ? ? ? ? ? max=score[i];
? ? ? ? }
? ? return max;
//計算最低分
int getMin(int score[])
? ? int min=100;
? ? ? ? if(score[i]<min)
? ? ? ? ? ? min=score[i];
? ? return min;
//分?jǐn)?shù)降序排序
void sort(int score[])
? ? int i,j;
? ? for(i=N-2;i>=0;i--)
? ? ? ? for(j=0;j<=i;j++)
? ? ? ? ? ? if(score[j]<score[j+1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int temp;
? ? ? ? ? ? ? ? temp=score[j];
? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=temp;
? ? ? ? ? ? }
? ? printScore(score);
int main()
? ? int score[N]={67,98,75,63,82,79,81,91,66,84};
? ? int sum,averange,max,min;
? ? sum=getTotalScore(score);
? ? averange=getAverange(score);
? ? max=getMax(score);
? ? min=getMin(score);
? ? printf("總分是:%d\n",sum);
? ? printf("平均分是:%d\n",averange);
? ? printf("最高分是:%d\n",max);
? ? printf("最低分是:%d\n",min);
? ? printf("----------成績排名---------\n");
? ? sort(score);
? ? return 0;
舉報
C語言入門視頻教程,帶你進(jìn)入編程世界的必修課-C語言
2 回答數(shù)組問題啊
3 回答3個數(shù)組元素題干沒給出
1 回答大神幫我看看啊我這個簡單的代碼運行出來的數(shù)字是負(fù)數(shù)!
2 回答大佬幫我看看清零數(shù)組!
1 回答我的這個是出了什么問題啊?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-02-08
對的 ,只是arr[]是形參 ,而arr1[]與arr2[]是實參 ,其中 arr1[]輸出的是數(shù)組中全部內(nèi)容,而arr2只是輸出了第一個元素的內(nèi)容?
2017-01-02
#include <stdio.h>
#define N 10
//打印分?jǐn)?shù)
void printScore(int score[])
{
? ? int i;
? ? printf("\n");
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? printf("%d",score[i]);
? ? }
? ? printf("\n");
}
//計算考試總分
int getTotalScore(int score[])
{
? ? int sum=0;
? ? inti;
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? sum+=score[i];
? ? }
? ? return sum;
}
//計算平均分
int AverangeScore(int score[])
{
? ? return getTotalScore/N;
}
//計算最高分
int getMax(int score[])
{
? ? int max=-1;
? ? int i;
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? if(score[i]>max)
? ? ? ? {
? ? ? ? ? ? max=score[i];
? ? ? ? }
? ? }
? ? return max;
}
//計算最低分
int getMin(int score[])
{
? ? int min=100;
? ? inti;
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? if(score[i]<min)
? ? ? ? {
? ? ? ? ? ? min=score[i];
? ? ? ? }
? ? }
? ? return min;
}
//分?jǐn)?shù)降序排序
void sort(int score[])
{
? ? int i,j;
? ? for(i=N-2;i>=0;i--)
? ? {
? ? ? ? for(j=0;j<=i;j++)
? ? ? ? {
? ? ? ? ? ? if(score[j]<score[j+1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int temp;
? ? ? ? ? ? ? ? temp=score[j];
? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=temp;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? printScore(score);
}
int main()
{
? ? int score[N]={67,98,75,63,82,79,81,91,66,84};
? ? int sum,averange,max,min;
? ? sum=getTotalScore(score);
? ? averange=getAverange(score);
? ? max=getMax(score);
? ? min=getMin(score);
? ? printf("總分是:%d\n",sum);
? ? printf("平均分是:%d\n",averange);
? ? printf("最高分是:%d\n",max);
? ? printf("最低分是:%d\n",min);
? ? printf("----------成績排名---------\n");
? ? sort(score);
? ? return 0;
}