Advertisement
Waliul

4. Find GCD of two numbers

Sep 10th, 2021
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.34 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int num1, num2, i, gcd;
  6.     printf("Enter two numbers : ");
  7.     scanf("%d %d", &num1, &num2);
  8.  
  9.     for(i = 1; i <= num1 && i <= num2; i++)
  10.     {
  11.         if((num1 % i == 0) && (num2 % i == 0))
  12.             gcd = i;
  13.     }
  14.  
  15.     printf("\nThe GCD of %d & %d is : %d\n", num1, num2, gcd);
  16.     return 0;
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement