Untitled
unknown
plain_text
2 years ago
472 B
18
Indexable
#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;
}Editor is loading...
Leave a Comment