Wednesday, December 28

Print Series of number using recursion in C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationDemo
{
    class PrintSeriesofNumberWithoutUsingLoop
    {
     
        public static void Main()
        {
            int no = 0, i = 1;
            Console.WriteLine("Enter no.");
            no = Convert.ToInt32(Console.ReadLine());
            Num v = new Num();
            v.print(i, no);
            Console.ReadLine();
        }
    }
    public class Num
    {
        public void print(int n,int nm)
        {
            if (n <= nm)
            {
                Console.WriteLine(n);
                n++;
                print(n, nm);
            }
        }
    }
}
Thanks shibashish mohanty

No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

.

ShibashishMnty
shibashish mohanty