Skip to main content

Program to accept two integer numbers and print the GCD(Greatest Common Divisor).

  Program to accept two integer numbers and print the GCD(Greatest Common Divisor).


CODE

πŸ‘‡

  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5.     int x, y, m, i;
  6.     printf("Enter 1st number : ");
  7.     scanf("%d", &x);
  8.     printf("Enter 2nd number : ");
  9.     scanf("%d", &y);

  10.     if (x > y)
  11.         m = y;
  12.     else
  13.         m = x;

  14.     for (i = m; i >= 1; i--)
  15.     {
  16.         if (x % i == 0 && y % i == 0)
  17.         {
  18.             printf("GCD of two number is : %d", i);
  19.             break;
  20.         }
  21.     }
  22. }

πŸ‘‰ExcuteπŸ‘ˆ


//OUTPUT                                                                                                                                    
/*

*/