Help me in solving RATINGINPRAC problem

My issue

i am facing difficulty

My code

#include <stdio.h>

int main(void) {
	int t;
	while(t--)
	{
	    int n;
	    int arr[n];
	    for(int i=0;i<n;i++)
	    {
	       scanf("%d",&arr[i]);
	    }
	
	for(int i=0;i<n;i++)
	{
	    if(arr[i+1]>=arr[i])
	    {
	        printf("yes");
	    }
	    else{
	        printf("no");
	    }
	}
	}
	
	return 0;
}


Learning course: Arrays using C
Problem Link: CodeChef: Practical coding for everyone

@khush79 There are a few errors I can see in your code.

  • You are not taking inputs for t and n.

  • You are declaring the array without taking size input first.

  • In the second for loop, the range is not correct according to the checking condition you have taken as, (i+1) will be out of bounds on last value.

  • Also, you have to check the whole array first then decide on the result but you are printing result for all i.

You can see my code for reference.

#include <stdio.h>

int main(void) 
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int i,n,c=1;
        scanf("%d",&n);
        int a[n];
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        
        for(i=1;i<n;i++)
        {
            if(a[i]<a[i-1])
            {
                c=0;
                break;
            }
        }
        if(c==0)
        {
            printf("NO\n");
        }
        else{
            printf("YES\n");
        }
        
    }
	
	return 0;
}

Here, i have taken a variable c initialized as (c=1).

In the second for loop, i am checking if current array index value is smaller than previous index value, if yes, i assign (c=0) and break from the loop.

In the end, i print the answer as either YES or NO depending on the value of c.