Program to find the factorial of a number using foreach extension method in C#

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 1066
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
class Program
static void Main(string[] args)
int input = 10; //Factorial of the neumber to find
int fact = 1; //a temporary variable to store the intermediate computed values

.Range(1, input)
.ForEach(i=> fact *= i);

//display the result
Console.WriteLine("Factorial of {0} is {1}", input, fact);


Factorial of 10 is 3628800

Comments or Responses

Login to post response