write a code using recursive function



Help for C/C++ for MVS, OS/390 C/C++, z/OS C/C++ and C/C++ Productivity Tools for OS/390

write a code using recursive function

Postby darvin13 » Thu Jul 01, 2010 4:26 pm

my problem:
i have to write a code using recursive function about arithmetic series in multiplication.

example:

the user will input two integers the length of the output and the difference, the output must start to 2.

Enter the length: 5 //this is not fixed
Enter the difference: 2 //this is not fixed

the output must be: 2 4 8 32 256

if you know the program please help me..
thanks :)
i need help..
nivrad13
darvin13
 
Posts: 4
Joined: Wed Jun 30, 2010 6:11 pm
Location: Philippines
Has thanked: 0 time
Been thanked: 0 time

Re: help me..

Postby Robert Sample » Thu Jul 01, 2010 4:50 pm

What have you written so far? Where are you stuck? Or are you expecting us to write your code for you?

And what, exactly, are the rules for taking your input to generate your output? For the example you give, 4 = 2 x 2, 8 = 4 x 2, 32 = 8 x 4, 256 = 32 x 8 so your multipliers are not even constant. Mathematically, an arithmetic progression has constant differences, not multiplications -- geometric progressions multiplies each term by a constant value to derive the next term. So you don't have a geometric progression, either. And whatever series you're supposed to be producing, recursion is pretty much not the way to do it -- recursion is good for factorials but not progressions.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: help me..

Postby enrico-sorichetti » Thu Jul 01, 2010 6:38 pm

the sequence is like a Fibonacci one with multiplication instead of the sum
every element is the product of the two preceding elements
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: help me..

Postby dick scherrer » Fri Jul 02, 2010 12:52 am

Hello,

You have now started 4 topics with the same question. . . :(

One more and they will all be deleted. . .

d
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post