Why is the code not wrking as i wrote

you are only checking for increasing sequence!,
you should first check for decreasing and then for increasing!
You can do this way:

  1. make i=1
  2. proceed uptill a[i]<a[i-1](make i++) and break whenever condition violates!
  3. with same i(don’t change it), proceed uptill a[i]>a[i-1]
  4. if i points at last element, so answer is true else answer is false.

what if i only want to check for the increasing sequences?

also how about his code?

@thakur0_0 follow instructions properly!

you don’t have to start again from 0,but from index where decreasing sequence stops!

whts wrong now? #include using namespace std; int checksequence(int a[100],int n){ int ans=0; int i; for(i=1;i<n;i++){ if(a[i]<a[i-1]){ ans=1; }else{ ans= 0; } } for(;i>0;i–){ if(a[i]>a[i-1]){ ans=1; }else{ ans= 0; } } return ans; } int main(){ int n; cin>>n; int a[1000]; for(int i=0;i<n;i++){ cin>>a[i]; } if(checksequence(a,n)){ cout<<“true”; } else{ cout<<“false”; } return 0; }

It’s still wrong as your ans depends upon what happens in last!
see code for this problem:


also have a habit to dry run your code on several test cases.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.