To generate all the subarrays of a given array O(n^3) !!!!
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,k;
cout<<"enter the size of array : \n";
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
cout<<"All subarrays are: ";
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
for(k=i;k<=j;k++)
cout<<a[k]<<" ";
cout<<endl;
}
}
}
Comments
Post a Comment