Posted by : sudhir chekuri Sunday, October 6, 2013

C# program greatest smallest number

It reads three numbers in runtime and displays the gre and greatest numbers.

CSharp program code

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("enter a number:");
            int a = Convert.ToInt32(Console.ReadLine());
            Console.Write("enter b number:");
            int b = Convert.ToInt32(Console.ReadLine());
            Console.Write("enter c number:");
            int c = Convert.ToInt32(Console.ReadLine());

            if (a > b && a > c)
            {
                Console.WriteLine("a is greatest number");
            }
            if (a < b && a < c)
            {
                Console.WriteLine("a is smallest number");
            }
            else if (b > a && b > c)
            {
                Console.WriteLine("b is greatest number");
            }
            if (b < a && b < c)
            {
                Console.WriteLine("b is smallest number");
            }
            else if (c > a && c > b)
            {
                Console.WriteLine("c is greatest number");
            }
            if (c < a && c < b)
            {
                Console.WriteLine("c is smallest number");
            }

            Console.ReadLine();
        }
    }
}

Output

Enter a number: 3
Enter b number: 5
Enter c number: 1
b is the greatest number
c is the smallest number


Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 MS DotNET Ninja - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -