Wednesday, 26 December 2012

GCD of two Numbers

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

namespace even
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            Console.WriteLine("Enter 'a' value");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter 'b' value");
            b = Convert.ToInt32(Console.ReadLine());
            while (a != b)
            {
                if (a > b)
                {
                    a = a - b;
                }
                else
                {
                    b = b - a;
                }
               
            }
            Console.WriteLine("GCD IS   " + b);

            Console.ReadLine();
        }
       
    }
}

No comments:

Post a Comment