473,406 Members | 2,956 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,406 software developers and data experts.

Recursion or Recursive Function

26
hi everyone..i need help on the code below. i want to convert it to a recursive function. can anyone help me..pls! thanks a lot!:)


Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2.  
  3. int main()
  4.  
  5. {
  6.     int i, j;
  7.     i=0;
  8.     while (i<=4) {
  9.         j=0;
  10.         while (j<=4) {
  11.            j++;
  12.         }
  13.         i++;
  14.     }
  15.     i++;
  16.  
  17.    cout << i*j;
  18. }
Feb 3 '07 #1
2 1598
Ganon11
3,652 Expert 2GB
What is the code doing right now? How do you think you'll implement a recursive algorithm to produce the same result?
Feb 3 '07 #2
Synapse
26
i didn't get what you mean...actually i've created a function from the code above that has a return value. here it is:

#include <iostream.h>
#include <stdlib.h>

int product (void);

int main()
{
system("CLS");
int Ans;
Ans=product();
cout << "The answer is " << Ans << endl;
return 0;
}

int product (void)

{
int i, j;
i=0;
while (i<=4) {
j=0;
while (j<=4) {
j++;
}
i++;
}
i++;

return i*j;
}

Th output of this code is 30..
How will i convert this to a recursive function then?
Feb 3 '07 #3

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

Similar topics

3
by: csx | last post by:
Hi all, Ive got a problem with recursion in Javascript. For this tree: http://www.pcm.uklinux.net/structure.jpg If you input node 3 (i.e. C) which is represented as 'values' in the array, it...
43
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
10
by: paulw | last post by:
Hi Please give problems that "HAS TO" to use recursion (recursive calls to itself.) Preferrably real world examples, not knights tour. I'm thinking about eliminating the use of stack... ...
9
by: John Pass | last post by:
I am trying to understand how recursion exactly works. See example (section) below: Say i = 4, then Number = 4 during 1st loop. Is Factorial(number - 1) automatically recognised as a recursive...
75
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their...
19
by: Kay Schluehr | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
20
by: athar.mirchi | last post by:
..plz define it.
10
by: slix | last post by:
Recursion is awesome for writing some functions, like searching trees etc but wow how can it be THAT much slower for computing fibonacci- numbers? is the recursive definition counting fib 1 to...
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.