GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers
Problem :- Given an array, write a program that prints 1 if array is sorted in non-decreasing order, else prints 0.
Submit Your Solution :- Click Here
Solution :-
#include <iostream>
using namespace std;
int main()
{
int t,arr[1000],i,j,n,k;
cin>>t;
while(t--)
{
cin>>n;k=0;
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<n-1;i++)
if(arr[i]>arr[i+1])
{
k=1; break;
}
if(k==0)
cout<<"1\n";
else
cout<<"0\n";
}
return 0;
}
Output:-
0 Comments: