1#include <stdio.h>
2int main()
3{
4 int n1, n2, i, gcd;
5
6 printf("Enter two integers: ");
7 scanf("%d %d", &n1, &n2);
8
9 for(i=1; i <= n1 && i <= n2; ++i)
10 {
11 // Checks if i is factor of both integers
12 if(n1%i==0 && n2%i==0)
13 gcd = i;
14 }
15
16 printf("G.C.D of %d and %d is %d", n1, n2, gcd);
17
18 return 0;
19}
20
1#include <stdio.h>
2int main()
3{
4 int n1, n2;
5
6 printf("Enter two positive integers: ");
7 scanf("%d %d",&n1,&n2);
8
9 while(n1!=n2)
10 {
11 if(n1 > n2)
12 n1 -= n2;
13 else
14 n2 -= n1;
15 }
16 printf("GCD = %d",n1);
17
18 return 0;
19}