Plz correct this code

Hey @devwrath1999
wont work for tc like this
5
1 4 5 6 7
Corrected ur code

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int i=0;
    while(i<n)
    {
     cout<<a[i];//removed ->
     int x=a[i]; //added
     while(i+1<n&& a[i+1]==(a[i]+1) ) //is i+1<n & it should come before than other 
     {
         i++;
     }
     if(x!=a[i])//added 
     cout<<"->"<<a[i]; //updated
     cout<<" ";//added
     if(i<n)
     i++;

    }
return 0;}

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.