Time limit exceeded error. what does it mean?

2019-09-21 21:57发布

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条回答
不美不萌又怎样
2楼-- · 2019-09-21 22:16

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

for(i=0;i<9;i++)
查看更多
登录 后发表回答