I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class csharpExercise
{
static void Main(string[] args)
{
int num,i;
long fact=1;
// Reading number
Console.Write("Enter any number to calculate factorial: ");
num = Convert.ToInt32(Console.ReadLine());
fact = 1;
i = 1;
//Run loop from 1 to number entered by user
while(i <= num)
{
fact = fact * i;
i++;
}
Console.Write("Factorial of : "+ num +" is " + fact);
Console.ReadLine();
}
}
I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..
Result:
Enter any number to calculate factorial: 5
Factorial of : 5 is 120
need an explanation for this answer? contact us directly to get an explanation for this answer