Tuesday, 3 April 2012

Sample Program Creation in c# Console Application

The sample program to find the factorial of a given number in c#...

Open a Console Application in Visual studio 2008, named it Factorial…
Then, Type the Below code in Program.cs, then compile and run…

Sample Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Factorial
    class Program
        static void Main(string[] args)
            int no = 0, fact = 1;
            Console.WriteLine("Enter the value to find factorial....");
            no = int.Parse(Console.ReadLine());
            Console.WriteLine("The factorial value is....");
            for (int i = 1; i <= no; i++)
                fact = fact * i;

Here, no = int.Parse(Console.ReadLine()); represents the explicit conversion.

That is, converting the string value into integer value…

To Build:  Cntl+Shift+B
To Run:    Press F5


No comments:

Post a Comment