using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace factorial
{
class Program
{
static void Main(string[] args)
{
int num, i, fact = 1;
//clrscr();
Console.WriteLine("\n >>C# PROGRAM TO FIND FACTORIAL OF GIVEN NUMBER <<\n");
Console.Write("\n Enter the Number whose Factorial you want: ");
num=Convert.ToInt32(Console.ReadLine());
for (i = num; i >= 2; i--) //i is intializing with num value and is decremented till 2
{
fact = fact * i; //fact is updating with changing value of i
}
Console.WriteLine("\n The factorial of {0} is {1}.\n\n", num, fact);
Console.ReadLine();
}
}
}
Output:

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace factorial
{
class Program
{
static void Main(string[] args)
{
int num, i, fact = 1;
//clrscr();
Console.WriteLine("\n >>C# PROGRAM TO FIND FACTORIAL OF GIVEN NUMBER <<\n");
Console.Write("\n Enter the Number whose Factorial you want: ");
num=Convert.ToInt32(Console.ReadLine());
for (i = num; i >= 2; i--) //i is intializing with num value and is decremented till 2
{
fact = fact * i; //fact is updating with changing value of i
}
Console.WriteLine("\n The factorial of {0} is {1}.\n\n", num, fact);
Console.ReadLine();
}
}
}
Output:
No comments:
Post a Comment