Thursday 18 October 2012

Factorial using for loop or without recursion in c sharp

Hi Friend's, Here I have written Factorial program without using recursion.

Code:

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

namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the number.....");
            Console.WriteLine(Factorial());
            Console.Read();
        }
        static long Factorial()
        {
            int n =Convert.ToInt32( Console.ReadLine());
            long Finalnumber = 1;
            for (int i = 1; i <= n;i++ )
            {
                Finalnumber = Finalnumber * i;
            }
            return Finalnumber;
          
        }
    }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.