473,767 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is recursion in c++.

..plz define it.
Jan 5 '08 #1
20 2999
On Sat, 05 Jan 2008 20:17:17 +0100, at**********@gm ail.com
<at**********@g mail.comwrote:
.plz define it.

RTFM !
Google is not dead !
Jan 5 '08 #2
"at**********@g mail.com" <at**********@g mail.comwrote in comp.lang.c++:
.plz define it.
Mainly "recursion" is where a function calls itself. Something like:

long unsigned Factorial(unsig ned const input)
{
if (0 == input) return 1;

if (1 == input) return input;

return input * Factorial(input - 1);
}

--
Tomás Ó hÉilidhe
Jan 5 '08 #3
On 2008-01-05 19:17:17 +0000, "at**********@g mail.com"
<at**********@g mail.comsaid:
.plz define it.
http://en.wikipedia.org/wiki/Recursion

Jan 5 '08 #4
On Jan 5, 2:17 pm, "athar.mir...@g mail.com" <athar.mir...@g mail.com>
wrote:
.plz define it.
As the English word suggests: a recursion is simply a function that
calls itself.
Which is neither efficient nor beneficial.
Each call generates a new local stack which eventually all need to be
unwound.
So in C++, its usually replaced with better alternatives.
An example of a preferred alternative would then be a function object
(functor).
Recursive functions have no state (what does that mean?).

To give you an example of recursion:
(that incidentally doesn't do what you'ld expect)

#include <iostream>

void recursion(int n)
{
std::cout << "n = ";
std::cout << n << std::endl;
if(n < 10)
recursion(++n);
}

int main()
{
recursion(0); // prints 11 times
}
Jan 5 '08 #5
On Jan 5, 2:23 pm, David Côme <davidc...@wana doo.frwrote:
On Sat, 05 Jan 2008 20:17:17 +0100, athar.mir...@gm ail.com

<athar.mir...@g mail.comwrote:
.plz define it.

RTFM !
Google is not dead !
And neither is a little respect.
Some come here hoping others do their homework,
others prefer to ask rather than remain clueless.
Some of those know very little English.

So please: if you feel the need to reply with a patronising remark,
consider ignoring them, redirecting them to Wikipedia/Google or offer
them a link to the FAQ.
Jan 5 '08 #6
On Jan 5, 2:19*pm, Salt_Peter <pj_h...@yahoo. comwrote:
On Jan 5, 2:17 pm, "athar.mir...@g mail.com" <athar.mir...@g mail.com>
Each call generates a new local stack which eventually all need to be
unwound.
So in C++, its usually replaced with better alternatives.

I agree. But my old college professors thought it was great.

And personally, I also find it more difficult to debug.
Jan 5 '08 #7
On Sat, 05 Jan 2008 21:41:38 +0100, Salt_Peter <pj*****@yahoo. comwrote:
On Jan 5, 2:23 pm, David Côme <davidc...@wana doo.frwrote:
>On Sat, 05 Jan 2008 20:17:17 +0100, athar.mir...@gm ail.com

<athar.mir...@ gmail.comwrote:
.plz define it.

RTFM !
Google is not dead !

And neither is a little respect.
Some come here hoping others do their homework,
others prefer to ask rather than remain clueless.
Some of those know very little English.

So please: if you feel the need to reply with a patronising remark,
consider ignoring them, redirecting them to Wikipedia/Google or offer
them a link to the FAQ.


You could have a basic question because everybody has been noob when he
started programmation.
Howerver before ask usenet,forums.. . you must make some research.

And recursion on google was the fisrt link so....

Jan 5 '08 #8
Salt_Peter <pj*****@yahoo. comwrote in comp.lang.c++:
As the English word suggests: a recursion is simply a function that
calls itself.
Which is neither efficient nor beneficial.

It's great though for template metaprogramming . For instance:

template<long unsigned x>
struct Factorial {
static long unsigned const val = x * Factorial<x-1>::val;
};

template<>
struct Factorial<1{
static long unsigned const val = val;
};

template<>
struct Factorial<0{
static long unsigned const val = 1;
}
--
Tomás Ó hÉilidhe
Jan 5 '08 #9
Tomás Ó hÉilidhe wrote:
Salt_Peter <pj*****@yahoo. comwrote in comp.lang.c++:
>As the English word suggests: a recursion is simply a function that
calls itself.
Which is neither efficient nor beneficial.


It's great though for template metaprogramming . For instance:

template<long unsigned x>
struct Factorial {
static long unsigned const val = x * Factorial<x-1>::val;
};

template<>
struct Factorial<1{
static long unsigned const val = val;
};

template<>
struct Factorial<0{
static long unsigned const val = 1;
}
recursion [ri-kur'zhen] - (n) see recursion

--
Jim Langston
ta*******@rocke tmail.com
Jan 5 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3903
by: Ken | last post by:
Hello, I have a recursive Sierpinski code here. The code is right and every line works fine by itself. I wish for all of them to call the function DrawSierpinski. But in this cae it only calls the first recusive function and at soon as n = 4 its stop. How do I go about so that all 8 lines get 4 recusion thanks ken
10
2523
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... Thanks.
8
1829
by: No bother | last post by:
I have a table with two columns, one named master, the other slave. Each column has a set of numbers. A number in one column can appear in the other. I am trying to see if there is any infinite recursion in the table. E.g.: Master Slave 1 2 2 1
19
2286
by: Kay Schluehr | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
6
2937
by: Andre Kempe | last post by:
hej folks. i have a heap with fixed size and want to determine the depth of a element with given index at compile-time. therefore i wrote some templates. however, when i use template index_properties<unsigned int>, i get a compiler-error, complaining about the template-recursion of __index_properties__. when i add a partially specialized template (the three commented lines) to stop the template-recursion, it works. does anyone how to...
6
1928
by: =?Utf-8?B?c2VlbWE=?= | last post by:
1) What will the value of txt be after executing MyFunction? public void Main() { string txt = MyFunction( “12345†); } public string MyFunction( string str ) { if( str.Length == 1 )
184
7115
by: jim | last post by:
In a thread about wrapping .Net applications using Thinstall and Xenocode, it was pointed out that there may be better programming languages/IDEs to use for the purpose of creating standalone, single executable apps. My goal is to create desktop applications for use on Windows XP+ OSs that are distributed as single executables that do not require traditional install packages to run. I would like to use a drag and drop UI development...
30
8307
by: Jeff Bigham | last post by:
So, it appears that Javascript has a recursion limit of about 1000 levels on FF, maybe less/more on other browsers. Should such deep recursion then generally be avoided in Javascript? Surprisingly, deep recursion actually isn't that slow for what I'm doing. Programming this task recursively is so much more straightforward to me, but currently I'm forced to use an ugly hack to avoid going over the 1000 level limit. Of course, it could...
35
4738
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
9571
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10009
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9838
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.