Saturday, June 18, 2016

C Program Code: Greatest Common Divisor

C Program Code

#include<stdio.h>
int main()
{
    int number1,number2,gcd,i;
    printf("Find Greatest Common Divisor in C \n");
    printf("Enter First Integer: ");
    scanf("%d",&number1);
    printf("Enter Second Integer: ");
    scanf("%d",&number2);
    gcd = 1;
    for( i = 1 ; i <= number1 && i <= number2 ; i++ )
    {
        if( number1%i == 0 && number2%i == 0)
            gcd = i;
    }
    printf("Greatest common divisor = %d \n",gcd);
    printf("Press enter to continue... \n");
    fflush(stdin);
    getchar();
    return 0;
}

Greatest Common Divisor in C Output Screenshot