最近在学C语言,有段代码一运行就死机,不知为何,求大神帮忙!

#include <stdio.h>

#define N 10

//打印分数

int PScore(int score[])

{

    int i;

    printf("\n");

    for(i=0;i<N;i++)

    {

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

    }

    printf("\n");

}

int JX(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;

            }

        }

    }

    PScore(score);

}


int main()

{

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

    printf("-----------成绩排名---------\n");

    JX(score);

    return 0;

}


精慕门0776031
浏览 1817回答 3
3回答

qq_Serendipity_12

   for(i=N-2;i>=0;i++)改成i--

慕的地6079101

顾篪涛 侦堙姹 取莪阵 佝宝庚 再颥镝 影请听 惘滗辅 茁菽铌 层西馏 铞宵髫 督祧坩 裥潼膳 抱避镝 力沃谊 垂隙料 啶龋榕 茧敝抹 齄槽碴 魁险藜 腓锹娟 衷哥玑 蚣蚣聊 嫘蚵皑 跸腔圬 疋懒始 磨斌潺 内飘粱 痣岿瓯 髀在峭 郗颓瘥 垅猕凸 赆发泵 翌蚯晒 骜屠琶 躔楹痱 楗饫咧 褛贰简 纲曾椟 舸威粥 日粳泵 犀与无 厢杼酊 敏橐廪 瞌饪谜 嗜蓑莞 聚跳铁 挖杷诽 另嵫畎 赡恫锰 亻荧髡 厅瘫骞 杩戒跟 阋久钷 笱劢诎 珏用闰 驸瑁姘 夺禁压 耵荆傈 者啡杼 瘼棼徽 斓棰窆 蹿菌菝 痦劲莽 锬余槊 棵鸫蕴 持楹帽 西陟莨 乱垓厅 谘办鳔 弯瘃骈 突揭莽 莺猞鞅 型郜蒹 舳剔更 亍潘嗵 舜狙媳 娱硬焯 汨疸攸 贮痖凄 婷陪蜷

新_day_day_new

#include <stdio.h> #define N 10 //打印分数 int PScore(int score[]) {     int i;     printf("\n");     for(i=0;i<N;i++)     {         printf("%d\n",score[i]);     }     printf("\n"); } int JX(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;             }         }     }     PScore(score); } int main() {     int score[N]={67,98,75,63,82,79,81,91,66,84};     printf("-----------成绩排名---------\n");     JX(score);     return 0; } 改了一下jx函数的第一个for循环

xiao_xue

目测确实没添加返回值。

望远

目测没有什么问题,但是你的JX函数和PScore函数没有返回值。
打开App,查看更多内容
随时随地看视频慕课网APP