hello !
i need to find the longest sub series by recursion , without use loops .
for example :
if the series:
arr = 45 1 21 3 33 6 53 9 18
the sub series are:
45 53
1 21 33 53
1 3 33 53
1 3 6 53
1 3 6 9 18
1 33 53
1 6 53
1 6 9 18
1 53
1 9 18
1 18
21 33 53
…….
and the longes sub series is 1 3 6 9 18
the function will return max = 5
this is my work , i`ve got some syntax error:
I would really appreciate any kind of help .....
=============== =============== =============== ============
int max_set(int arr[], int size, int state=1 ,int i=0, int max=0)
{
printf ("Please enter the size of the array\n");
scanf("%d",size );
if (size<=0)
return(0);
else
printf ("Please enter "%d" values for the array\n", size);
gets (arr);
check_arr_value s(arr, size, state, i);
if (max<=state)
max=state;
max_set(arr, size, state=1, i++, max);
printf ("%d", max);
return(state);
}
int check_arr_value s(int arr[], int size, int state, int i)
{
if ((arr[i]<=arr[i+1])&&(i<=size))
state++;
check_arr_value s(arr, size, state, i++);
}
#include<stdio. h>
main()
{
}
i need to find the longest sub series by recursion , without use loops .
for example :
if the series:
arr = 45 1 21 3 33 6 53 9 18
the sub series are:
45 53
1 21 33 53
1 3 33 53
1 3 6 53
1 3 6 9 18
1 33 53
1 6 53
1 6 9 18
1 53
1 9 18
1 18
21 33 53
…….
and the longes sub series is 1 3 6 9 18
the function will return max = 5
this is my work , i`ve got some syntax error:
I would really appreciate any kind of help .....
=============== =============== =============== ============
int max_set(int arr[], int size, int state=1 ,int i=0, int max=0)
{
printf ("Please enter the size of the array\n");
scanf("%d",size );
if (size<=0)
return(0);
else
printf ("Please enter "%d" values for the array\n", size);
gets (arr);
check_arr_value s(arr, size, state, i);
if (max<=state)
max=state;
max_set(arr, size, state=1, i++, max);
printf ("%d", max);
return(state);
}
int check_arr_value s(int arr[], int size, int state, int i)
{
if ((arr[i]<=arr[i+1])&&(i<=size))
state++;
check_arr_value s(arr, size, state, i++);
}
#include<stdio. h>
main()
{
}
Comment