Sunday, 22 September 2013

Console Application : Simple Factorial Program.

Steps To Create Factorial's Program in Console Application.

1. Create New Console Application Program
2. Name It As "Factorial".
3. Open Program.cs.
4. Replace Your Program.cs Code With Below Code.

Program.cs


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

namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "Factorial";
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Enter The Number = ");
            int n = Int32.Parse(Console.ReadLine());
            int fact = 1;
            int i;
            for (i = n; i > 0; i--)
            {
                fact = fact * i;

            }
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Factorial is = " + fact);
            Console.ReadKey();

        }
    }
}


5. Compile And Run Your Console Application Project.
6. Kindly Enter The Particular Value To Get It's Factorial.

My Output.



All The Best :)

Saturday, 21 September 2013

Console Application : Console Color

We Can Give Colors To Console Text.
This Is Very Small And Simple Tutorial.

You Can Give Foreground Color Using  "Console.ForegroundColor = ConsoleColor.Green;" this code.
And Background Color Using "Console.BackgroundColor = ConsoleColor.Blue;"
We Can Set Title To Console Using "Console.Title = "Custom Console Title";".

1. Create New Console Application Program Name It As CusomConsole.
2. Now Replace Your Program.cs with Below Code.

Program.cs


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

namespace CustomConsole
{
    class Program
    {
        static void Main(string[] args)
        {             
            Console.ForegroundColor = ConsoleColor.Green;
            Console.BackgroundColor = ConsoleColor.Red;
            Console.Title = "Custom Console Title";
            Console.WriteLine("This Is Coloured Text");
            Console.ReadLine();


        }
    }
}


3. Now Compile And Run Your Application.
You Will Have Titled And Color Text As Output.

My OutPut Is Given Below.



All The Best :)


Thursday, 19 September 2013

Console Application : Fibonacci Series.

Create new Console Application Project And Name It As FibonacciSeries.
Now Just Change Your Program.cs With Below Code.

Program.cs


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

namespace FibonacciSeries
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Series Upto..?");

            int d = int.Parse(Console.ReadLine());

            int a = -1; int b = 1;

            for (int i = 0; i < d; i++)
            {
                int sum = b + a; a = b;
                b = sum;
                Console.WriteLine(b);
            }
            Console.WriteLine("Type and enter to close.");
            Console.ReadLine();
           
        }
    }
}
 

Now Compile And Run The Project.
Enter The Term Upto Which We Want The Fibonacci Series.

My Output's Are As Below.





  All The Best :)
Console Application : Prime Number

Prime Number are the Numbers Which Are Those Number Which are Divisible By 1 And Only Those Number. Eg . 5 which is Divisible By 1 And 5 Only.

Create New Console Application Program And Name It as primeno
Replace Your Program.cs with below Code.

Program.cs



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

namespace primeno
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, f = 0;
            Console.WriteLine("Enter Any No. :");
            n = Int32.Parse(Console.ReadLine());
            for (int i = 2; i < n; i++)
            {
                if (n % i == 0)
                    f = 1;
            }

            if (f == 0)
                Console.WriteLine("Given no. "+n+" Is a Prime Number");
            else
                Console.WriteLine("Given no. " + n + " Is Not a Prime Number");

            Console.ReadKey();
        }
    }
}

Ww Will Take the Input Number In integer 'n' and then we will try to devide it by every possible number which are minimum than input number.

Now Compile And Run Your Project And Enter Any Number And Check Whether It is Prime Number Or Not.
My Output's Are as Below






 


 All The Best :)