Saturday, 28 April 2018

Find the factorial through ForEach condition

Find the factorial through forEach condition
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationSample
{
    class FactForEach
    {
        public static void Main()
        {
            int b;
            int[] c = new int[1];
            Console.Write("Enter No...> ");
          b= Int32.Parse(Console.ReadLine());
            int i, a = 1;
            for (i = 1; i <= b; i++)
            {
                a = a * i;
            }
            Console.WriteLine();
            c[0] = a;
            foreach (int cb in c)
            {
                Console.WriteLine("Factorial = " + cb);
                Console.ReadLine();
            }
        }
    }
  }

0 comments

Post a Comment