Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _17.CalculateGCD
- {
- class CalculateGCD
- {
- static void Main()
- {
- Console.Write("Enter a number a: ");
- int a = int.Parse(Console.ReadLine());
- Console.Write("Enter a number b: ");
- int b = int.Parse(Console.ReadLine());
- int gcd = 1;
- int tempA = 0;
- int tempB = 0;
- Console.WriteLine("The prime divisors of a are: ");
- for (int i = a; i >= 1; i--)
- {
- if (a % i == 0)
- {
- tempA = a / i;
- }
- else
- {
- continue;
- }
- Console.Write("{0} ", tempA);
- }
- Console.WriteLine();
- Console.WriteLine("The prime divisors of b are: ");
- for (int j = b; j >= 1; j--)
- {
- if (b % j == 0)
- {
- tempB = b / j;
- }
- else
- {
- continue;
- }
- Console.Write("{0} ", tempB);
- }
- Console.WriteLine();
- if (a > b)
- {
- for (gcd = b; gcd >= 1 ; gcd--)
- {
- if ((a % gcd == 0) && (b % gcd) == 0)
- {
- Console.WriteLine("Greatest divisor of a and b: {0}.", gcd);
- break;
- }
- else
- {
- continue;
- }
- }
- }
- if (b > a)
- {
- for (gcd = a; gcd >= 1 ; gcd--)
- {
- if ((b % gcd == 0) && (a % gcd) == 0)
- {
- Console.WriteLine("Greatest divisor of a and b: {0}.", gcd);
- break;
- }
- else
- {
- continue;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement