All Type Coding

Search Here

How do I find greatest number out of 7 numbers in c#.?

using System;

class abc
{
    int a, b, c, d, e, f, g;
    public void grt()
    {
        Console.WriteLine("Enter first no that is a");
        a = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter second no that is b");
        b = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter third no that is c");
        c = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter third no that is d");
        d = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter third no that is e");
        e = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter third no that is f");
        f = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter third no that is g");
        g = Convert.ToInt32(Console.ReadLine());

        if ((a > b) && (a > c) && (a > d) && (a > e) && (a > f) && (a > g))
        {
            Console.WriteLine("a is greater");
        }
        else if ((b > a) && (b > c) && (b > d) && (b > e) && (b > f) && (b > g))
        {
            Console.WriteLine("b is greater");
        }
        else if ((c > a) && (c > b) && (c > d) && (c > e) && (c > f) && (c > g))
        {
            Console.WriteLine("c is greater");
        }
        else if ((d > a) && (d > b) && (d > c) && (d > e) && (d > f) && (d > g))
        {
            Console.WriteLine("d is greater");
        }
        else if ((e > a) && (e > b) && (e > c) && (e > d) && (d > f) && (d > g))
        {
            Console.WriteLine("e is greater");
        }
        else if ((f > a) && (f > b) && (f > c) && (f > d) && (f > e) && (f > g))
        {
            Console.WriteLine("f is greater");
        }
        else
        {
            Console.WriteLine("g is greater");
        }
        Console.ReadKey();
    }
}
class grt2
{
    public static void Main(string[] args)
    {
        abc a = new abc();
        a.grt();
    }
}
Output

No comments :

Post a Comment