請(qǐng)問(wèn)為什么把最低分代碼段加進(jìn)來(lái)就運(yùn)行失敗了呢,注釋掉最低分,最高分就運(yùn)行成功。最低分有問(wèn)題嗎?
#include <stdio.h>
int main()
{
? ? int score[]={67,98,75,63,82,79,81,91,66,84};
? ? int zongFen();
? ? int max();
? ? int min();
? ? printf("總分:%d\n",zongFen(score));//總分
? ? printf("最高分:%d\n",max(score));//總分
? ? printf("最低分:%d\n",min(score));//總分
? ? return 0;
}
//最低分
int min(int score[])
{
? ? int n;
? ? for(int i=0;i<10;i++)??
? ? {
? ? ? ? for(int j=9;j>=i;j--)
? ? ? ? {
? ? ? ? ? ? if(score[j]<score[j-1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? n=score[j];
? ? ? ? ? ? ? ? score[j]=score[j-1];
? ? ? ? ? ? ? ? score[j-1]=n;
? ? ? ? ? ? }
? ? ? ? }
? ? ??
? ? }
? ? return n;
}
//最高分
int max(int score[])
{
? ? int m;
? ? for(int i=0;i<10;i++)??
? ? {
? ? ? ? for(int j=9;j>=i;j--)
? ? ? ? {
? ? ? ? ? ? if(score[j]>score[j-1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? score[j-1]=score[j];
? ? ? ? ? ? ? ? m=score[j-1];
? ? ? ? ? ? }
? ? ? ? }
? ? ??
? ? }
? ? return m;
}
//總分
int zongFen(int score[])??
{
? ? int sum;
? ? for(int i=0;i<10;i++)
? ? {
? ? ? ?sum+=score[i];?
? ? }
? ? return sum;
? ??
}
2021-10-20
你主函數(shù)中,不需要將zongFen等重新定義,且int min()函數(shù)求最小值時(shí)有問(wèn)題