Caravans problem-getting wrong answer even thought the output results are correct

#include <stdio.h>
#include <stdlib.h>

int main()
{
int t;
scanf("%d",&t);
while(t–)
{
long int n,i;
scanf("%ld",&n);
int c[n];

    for(i=1;i<=n;i++)
    scanf("%d",&c[i]);
    int max=c[1],count=0;
    for(i=2;i<=n;i++)
    {
        if(c[i]<=max)
            {max=c[i];count++;}
    }

    printf("%d",count+1);
    }

return 0;

}

1 Like

Try increasing the array size to n+1 instead of n. You are using elements 1…n from the array while you have allocated only n elements [0…n-1].

Also you are not printing a new line at the end of each test case :slight_smile:

Replace: printf("%d",count+1);
With: printf("%d\n",count+1);