Yes, the code seems to be incorrect.
#include <stdio.h>
int is_contiguous ( int a[], int size )
{
int i;
for(i=0;i<size-1;i++){
if(a[i+1]-a[i]!=1){ /* not strictly increasing */
break;
}
}
if ( i == size ){ /* strictly increasing */ //should be size-1
return 0;//should be return 1;
}
if ( i == 0){
for(i=0;i<size-1;i++){
if(a[i]-a[i+1]!=1){ /* not strictly decreasing */
return 0;
}
}
return 1;//should be return 0;
} else{
return 0;
}
}
int main() {
int a[5];
int size = 5;
a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;
a[4] = 5;
int ans;
ans = is_contiguous(a, size);
printf("%i\n", ans);// 0 is printed but as per the question 1 should be printed
return 0;
}