473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

help: find max sub series

36
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_values(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_values(int arr[], int size, int state, int i)
{
if ((arr[i]<=arr[i+1])&&(i<=size))
state++;
check_arr_values(arr, size, state, i++);
}

#include<stdio.h>
main()
{
}
Jan 9 '09 #1
3 2795
boxfish
469 Expert 256MB
Try moving the #include up to the very top of your program. You need to have stdio.h included before you use stuff like printf, which is defined in stdio.h. In general, put includes at the top of your programs. Hope this helps, and please use code tags around your code. Put [CODE] before it and [/CODE] after it so it shows up in a code box. Thanks.
Jan 9 '09 #2
weaknessforcats
9,208 Expert Mod 8TB
I suggest you get this working by using a loop. Any recursion is replaceable with a loop. After it works, the guts of the loop become your recursive function and the loop controls are moved to the top of the function to stop the recursion at the correct point.
Jan 10 '09 #3
Bassem
344 100+
I do think the same as weaknessforcats said.
Recursive functions add overhead for your program, and only used when it make the code more readable and get more to reality.
And it can be transform between them.
Jan 10 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sriram Krishnan [at] gmx [dot] net | last post by:
Given an arbitrary number series, how do I identify the series and find the Nth number... for e.g 1,3,5,7 is an AP and the next number will be 9 1,8,27,64 is the series of cubes and the next will...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
1
by: Sriram Krishnan [at] gmx [dot] net | last post by:
Given an arbitrary number series, how do I identify the series and find the Nth number... for e.g 1,3,5,7 is an AP and the next number will be 9 1,8,27,64 is the series of cubes and the next will...
2
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the...
0
by: JonathanParker | last post by:
Hello, Wondered if you could help me with a little issue I'm having. I'm exporting some data from Access to Excel and converting into some fancy graphs. The number of series' ranges from 2 to 5....
1
by: hiteshguptapec | last post by:
hi everybody, i am learning c programing at home with the help of net but is not able to solve one Q/A can any one please help me these Q/A....... i shall be very thank full to...
2
by: cNoob | last post by:
I need to write a program to find the sum, sum of squares, sum of the cubes, and sum of a certain series shown below for the first n integers, begining with 1 and ending with n = 100. Summing the...
6
by: deepner | last post by:
plz help to find why the program showing fibonacci(non-recursively) is running infinitely #include<iostream> #include<conio.h> using namespace std; unsigned int fibo(int a,int b) { unsigned...
20
by: WanYee | last post by:
Hi, my name is WanYee, i need some help on an application i am currently doing, the application is like a calculator to find current resistance and etc... of a series-parallel circuit, my problem...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.