| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 362 人关注过本帖
标题:程序运行时出错,求解
只看楼主 加入收藏
幽灵X
Rank: 5Rank: 5
等 级:职业侠客
帖 子:128
专家分:328
注 册:2013-1-28
结帖率:80%
收藏
 问题点数:0 回复次数:1 
程序运行时出错,求解
程序运行时出错,求解
#include
main()
{
    int scores[6]={45,66,95,89,76};
    int i,j,temp;
    printf("原成绩表:\n");
    for(i=0;i<=4;i++)
        printf("%4d",scores[i]);
    printf("\n********************************\n");
    printf("输入需要插入的成绩:");
    scanf("%d",&scores[i]);
    for(i=0;i<=5;i++)
        for(j=0;j<=5-i;j++)
            if(scores[j]<SCORES[J+1])
            {
                temp=scores[j];
                scores[j]=scores[j+1];
                scores[j+1]=temp;
            }
    printf("新成绩表:\n");
    for(i=0;i<=5;i++)
        printf("%4d",scores[i]);
    printf("\n");
    return 0;
}
搜索更多相关主题的帖子: include scores 成绩表 
2013-01-28 19:00
caoboxx
Rank: 1
来 自:广西柳州
等 级:新手上路
帖 子:10
专家分:9
注 册:2013-1-22
收藏
得分:0 
#include<stdio.h>
int main()
{
    int scores[6]={45,66,95,89,76};
    int i,j,temp;
    printf("原成绩表:\n");
    for(i=0;i<=4;i++)
        printf("%4d",scores[i]);
    printf("\n********************************\n");
    printf("输入需要插入的成绩:");
    scanf("%d",&scores[i]);
    for(i=0;i<=5;i++)
        for(j=0;j<=5-i-1;j++)
            if(scores[j]<scores[j+1])
            {
                temp=scores[j];
                scores[j]=scores[j+1];
                scores[j+1]=temp;
            }
    printf("新成绩表:\n");
    for(i=0;i<=5;i++)
        printf("%4d",scores[i]);
    printf("\n");
    return 0;
}

在排序的时候数组越界了,当j=5的时候 scores[j]<scores[j+1] 这个语句 等效于 scores[5]<scores[5+1]
而scores[6]已经超出数组的范围了
2013-01-29 14:21
快速回复:程序运行时出错,求解
数据加载中...
 
   



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

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