Find the maximum length of the subarray in increasing order.

For example we have an array {5,4,6,-2,-1,0,1,9}. The biggest sub-array in increasing order is: {-2,-1,0,1,9}. So the length is 5.

#include<stdio.h>
void main () {
int arr[8] = {5,4,6,-2,-1,0,1,9},i,arrn[8],count=1,j=0,max;
printf("The given array is: ");
for(i=0;i<8;i++)
printf(" %d" ,arr[i]); // printing the actual array - unnecessary step.
printf("\n");
for(i=0;i<7;i++){
if(arr[i]<arr[i+1])
{
count++;
}
else
{
arrn[j]=count; // adding the length of sub array
count=1;
j++;
}
}
arrn[j]=count; // adding the final length
max=arrn[0];
printf("Length of sub arrays in increasing order");
for(i=0;i<=j;i++){
if(max<arrn[i])
max=arrn[i];
printf(" %d",arrn[i]); // printing the new array - unnecessary step.
}
printf("\n Maximum Length of the substring: %d",max); // print max value
}

   

Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C