473,659 Members | 2,671 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.Substrin g( startIndex, length )
Aug 13 '07 #1
6 1924
seema,

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

"seema" <se***@discussi ons.microsoft.c omwrote in message
news:81******** *************** ***********@mic rosoft.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.Substrin g( 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.c omwrote in
message news:e9******** ******@TK2MSFTN GP04.phx.gbl...
seema,

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

"seema" <se***@discussi ons.microsoft.c omwrote in message
news:81******** *************** ***********@mic rosoft.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.Substri ng( startIndex, length )



Aug 13 '07 #3
Hi,

Just run it using the debugger

"seema" <se***@discussi ons.microsoft.c omwrote in message
news:81******** *************** ***********@mic rosoft.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.Substrin g( startIndex, length )


Aug 13 '07 #4

On Aug 13, 8:54 pm, "Smithers" <A...@B.comwrot e:
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.Substrin g( 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.Substrin g( startIndex, length )

Aug 14 '07 #7

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

Similar topics

9
2678
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 doesn't need explanation).
9
2334
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, (using time?). Sims
58
4657
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 (PHONE_LIST, "_+")) { Console.WriteLine (phoneNumber); } } Output: 495.1000
7
1813
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 that when you specify a second argument the number of elements specified in the first argument is each in turn set to the second argument. void Foo::bar(int x) { static std::vector<int> foo; std::cout << "source: " << x << std::endl;...
2
6452
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_ { char szInput; char szOutput; int iSum;
24
2684
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
2881
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 & , int * , int , bool );
23
4857
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
2692
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" xmlns:soapenc="http:// schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/ XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/...
69
3173
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 little pointers, obviously I avoid using them. A few days ago when I was reading a book about programming, I was told that pointers are the very essence of C language, if I couldn't use it well, I'm a bad programmer, it's a big shock. So now I'm...
0
8427
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7355
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
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
4175
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
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.