/**********************************************************************
GCD Using for loop and if Statement using C Program
**********************************************************************/
#include <stdio.h>
int main()
{
int number_1, number_2, i, gcd;
printf("Enter two integers: ");
scanf("%d %d", &number_1, &number_2);
for(i=1; i <= number_1 && i <= number_2; ++i)
{
// Checks if i is factor of both integers
if(number_1%i==0 && number_2%i==0)
gcd = i;
}
printf("G.C.D of %d and %d is %d", number_1, number_2, gcd);
return 0;
}
/*
OUTPUT:
Enter two integers: 12
3
G.C.D of 12 and 3 is 3
*/
Leave a Reply