Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
472 B
9
Indexable
Never
#include <stdio.h>
int main()
{
    int num, n;
    printf("Enter number: ");
    scanf("%d",&num);
    printf("Enter n: ");
    scanf("%d",&n);
    for (int j = n; j > 0; j--)
    {
        int i, gcd;
    
    
        for(i=1; i <= j && i <= num; ++i)
        {
            // Checks if i is factor of both integers
            if(num%i==0 && j%i==0)
                gcd = i;
        }
    
        printf("GCD of %d and %d is %d\n", j, num, gcd);
    }
    return 0;
}
Leave a Comment