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);
}
you are indexing two past the end of the array. you need to make the for condition this: