Quick actions

cmd+k|ctrl+k

Navigation

Languages

GCD

Snippet info

Language

Csharp

Visibility

public

Author

danielmg17

Created

2016-12-15T18:05:14Z

Updated

2016-12-15T18:38:15Z

using System;

class MainClass
{
    static void Main()//doesn't work with prime numbeers
    {
        Console.Write("First Int: ");
        int x = Convert.ToInt32(Console.ReadLine());
        Console.Write(x+"\nSecond Int: ");
        int y = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine(y);
        int z, GCD;
        bool first = true;
        if(x<y)
        {
            z = y%x;
            first = false;
        }
        else z = x%y;
        if(z==0)
        {
            if(first)
                GCD = y;
            else GCD = x;
        }
        else GCD = z;
        Console.WriteLine("GCD = {0}",GCD);
    }
}
INFO