#include<bits/stdc++.h>
using namespace std;
bool sorted(int n,int *a,int i)
{
if(i==n-1)
{
return true;
}
if(a[i]>a[i+1])
{
return false;
}
sorted(n,a,i+1);
}
int main() {
int n;
cin>>n;
int a[n]={0};
for(int i=0;i<n;i++)
cin>>a[i];
if(sorted(n,a,0))
cout<<“true”;
else
cout<<“false”;
return 0;
}
Program giving compilation error while working on other ide
@jha.aparna17
When you are calling the function sorted(n, a, i + 1), you are not returning it. Use return sorted(n, a, i + 1) and it will work out.
If my explanation was able to answer your query, please mark the doubt as resolved.