How to print 1 to 100 number without using forloop in C#

Posted by Shubham under C# category on | Points: 40 | Views : 10852
using System;
class recurs
public void recursivePrint(int i)

if (i <= 100)
Console.WriteLine(i + "");

class neww
public static void Main()
recurs re = new recurs();


Comments or Responses

Posted by: T.Saravanan on: 3/4/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Nice try. If i use '1000', the print method call '1000' times. In this time method parameter initialize more than time. Please compare with loop concept which is take more time.

Kindly post your code inside the code tag.
Posted by: Puneet20884 on: 3/5/2012 Level:Bronze | Status: [Member] | Points: 10
A simple way to illustrate the recursion and the very nice explanation by the moderator too why not efficient.

A suggestion, if in the worst case this approach is required to be used, the class "recurs" should be taken as singleton one, so that at least the same object may not get created everytime.

Kindly correct me if not appropriate.
Posted by: Shubham on: 3/6/2012 Level:Starter | Status: [Member] | Points: 10
i m agree wid your response but this code is example of recursion method simply you have to know how the recursion works thts why i m only gives example to print 1-100 digit.....
if u r print 1000 time thats is worst case for this program........

Login to post response