C Program to Calculate the GCD of Two Numbers using For Loop
Write a Program to Calculate the GCD of Two Numbers using For Loop
// C Program to Calculate the GCD of Two Numbers using For Loop #include <stdio.h> int main() { int n1, n2, m, n; printf("Enter number 1 :--> "); scanf("%d", &n1); printf("Enter number 2 :--> "); scanf("%d", &n2); m = n1; n = n2; for(; n1 != n2; ) { if(n1 > n2) { n1 = n1 - n2; } else { n2 = n2 - n1; } } printf("GCD of %d and %d is %d ", m, n, n1); return 0; }
Output:
Enter number 1 :--> 220
Enter number 2 :--> 430
GCD of 220 and 430 is 10