Q:

Write a C# Sharp program to calculate the factorial of a given number

0

Write a C# Sharp program to calculate the factorial of a given number

Sample Output:

Calculate the factorial of a given number:                                                                    
--------------------------------------------                                             
Input the number : 6                                                                                          
The Factorial of 6 is: 720

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;  
public class Exercise15  
{  
    public static void Main()
{
  int i,f=1,num;
  
	Console.Write("\n\n");
    Console.Write("Calculate the factorial of a given number:\n");
    Console.Write("--------------------------------------------");
    Console.Write("\n\n");  

  Console.Write("Input the number : ");
   num= Convert.ToInt32(Console.ReadLine()); 
  for(i=1;i<=num;i++)
      f=f*i;

  Console.Write("The Factorial of {0} is: {1}\n",num,f);
 }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now