473,505 Members | 13,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is Output

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 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )
Aug 13 '07 #1
6 1916
seema,

Have you compiled this and seen what will be output?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"seema" <se***@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
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 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )


Aug 13 '07 #2
It looks like someone doesn't want to do their own homework... will
eventually become a professional meeting attender (if not burger flipper).

-S

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:e9**************@TK2MSFTNGP04.phx.gbl...
seema,

Have you compiled this and seen what will be output?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"seema" <se***@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
>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 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )



Aug 13 '07 #3
Hi,

Just run it using the debugger

"seema" <se***@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
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 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )


Aug 13 '07 #4

On Aug 13, 8:54 pm, "Smithers" <A...@B.comwrote:
It looks like someone doesn't want to do their own homework...
Bingo. The typographic quotes are a dead giveaway. =]

Aug 13 '07 #5
seema wrote:
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 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )
Not really a good hint as that gives no clue as to what will happen.
BTW, this is not the way I would code this, but it appears the goal was
to test the ability to follow a code path through a recursive function
without the aid of a debugger other than your internal debugger (the one
between your ears).
--
Tom Porterfield
Aug 13 '07 #6
My Grandmother used to say that the way to learn about recursion is to study
recursion. She lived to be 100, by the way. It wasn't recursion that killed
her though. I think she had a stack overflow from some Clan McGregor scotch...
--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"seema" wrote:
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 )
return str;
else
return MyFunction(str.Substring(1, str.Length - 1)) + str.Substring(0,1);
}
Hint:
String.Substring( startIndex, length )

Aug 14 '07 #7

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

Similar topics

9
2674
by: Glutinous | last post by:
Trying to learn php, and came across =& as in $form =& $HTTP_POST_VARS; I can't find any reference to =&, with no success in searching for a definition (as though it's _so_ obvious it...
9
2329
by: Sims | last post by:
Hi, I recall a function that would tell me how long it took to generate an output. But for the life of me I cannot remember it. Dow anybody know it? Or do I have to write something myself,...
58
4614
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split...
7
1801
by: Neil Zanella | last post by:
OK, this time the compiler's got me a little bit puzzled, simply because it is doing something I am not expecting. My understanding, according to the documentation of std::vector<>::resize(), is...
2
6449
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
24
2663
by: kalamantina | last post by:
#include "stdafx.h" #include <stdio.h> #define output( x ) printf( #x "\r\n" );fflush( stdout ) class CMyBase { public: CMyBase() { output( CMyBase() ); f(*this);
1
2869
by: aboood | last post by:
Hi guys Could any one tell me what does that code do please? in pseudo-code #include <fstream.h> #include <iostream.h> bool differsByOneDigit ( int , int ); void outputResults ( ofstream & ,...
23
4828
by: mahesh | last post by:
Hi all, I have following code that is supposed to increase the power by specified value. int main() { system("cls"); int i, exponent; double base; double new_base=0.0;
0
2678
by: Philluminati | last post by:
I have a Perl SOAP Server which returns this SOAP Message when invoked: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance"...
69
3128
by: Yee.Chuang | last post by:
When I began to learn C, My teacher told me that pointer is the most difficult part of C, it makes me afraid of it. After finishing C program class, I found that all the code I wrote in C contains...
0
7213
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
7098
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...
0
7298
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
7366
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...
1
7017
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
5610
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 projectplanning, coding, testing,...
0
3187
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...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.