Time limit exceeded error. what does it mean?

ⅰ亾dé卋堺 提交于 2019-12-13 11:18:47

问题


I want to write a C program that prints the maximum of 10 integer numbers. but i get this error. what is the problem?(error is: time limit exceeded)

int main()

{
    int arr[9];
    int i;
    int max=-1;

    for(i=0;i<=10;i++) {
        scanf("%d",&arr[i]);

        if(arr[i]>arr[i+1]){
            arr[i]=max; 
        }  
    }
    printf("%d",max);
 }

program works like that,thank u for help

int main()

{
    int arr[9];
    int i;


       int max=-1;



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

        scanf("%d",&arr[i]);

        if(arr[i]>max) {

            max=arr[i]; }  }

            printf("%d",max);

    }

回答1:


you are indexing two past the end of the array. you need to make the for condition this:

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


来源:https://stackoverflow.com/questions/24745307/time-limit-exceeded-error-what-does-it-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!