GCD Program in C - C Program to find GCD Using for loop and if Statement



 c program to find gcd using for loop and if statement

Learn C - C tutorial - c program to find gcd using for loop and if statement - C examples - C programs

C Program to find GCD Using for loop and if Statement

  • GCD(Greatest Common Divisor) of two or more numbers, which are not all zero, is the largest positive numbers that divide the numbers without a remainder.
  • For example,GCD of two numbers 8 and 12 is 4.

Sample Code

#include <stdio.h>
int main()
{
    int num1=7, num2=4, i, gcd;
    printf("Two integers:7,4\n ");
    for(i=1; i<=num1 && i<=num2; ++i)
    {
        if(num1%i==0 && num2%i==0)
            gcd = i;
    }
    printf("G.C.D of %d and %d is %d", num1, num2, gcd);
    return 0;
}

Output

Two integers:7,4
 G.C.D of 7 and 4 is 1


View More Quick Examples


Related Searches to GCD Program in C - C Program to find GCD Using for loop and if Statement