FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 106   



Following program shows you how to print factorial of given number.
In this program we get input from user and prints factorial of that number using for loop

using System;

class MainClass {
  public static void Main (string[] args) {
    Console.WriteLine("Enter a number:");
    int input = Convert.ToInt32(Console.ReadLine());
    int result = 1;
    for (int i = 1; i <= input; i++) {
      result = result * i;
    }
    Console.WriteLine(input + " factorial is: " + result);
  }
}

Output:

Enter a number:
 6
6 factorial is: 720



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News