您好,我尝试进行一次大学练习,以在没有math.h库的情况下计算GCD!我已经写了这段代码,但我不明白为什么我的代码为什么不能进入(最小,最大)计算的if语句!似乎该代码没有给出我想要的if语句条件的结果!我已经尝试了一切!请知道发生了什么事吗?
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000
int main(void)
{
int n;
int i, j, a;
int counter2 = 0;
int large;
int small;
int rem, gcd;
int max=INT_MIN,min=INT_MAX;
int achilles;
scanf("%d", &n);
printf("%d = ",n);
for (i = 1; i <= n; i++)
{
int count = 0;
for (j = 1; j <= i; j++)
{
if (i % j == 0)
{
count++;
}
}
int l = 0;
if (count == 2)
{
int expo;
while (n % i == 0) // calculate factor and his exponent
{
l++;
n = n / i;
}
expo=l;
if (expo > max) // calculates min and max in order to find GCD
{
max = expo;
large = max;
}
if (expo < max)
{
min = expo;
small = min;
}
}
//large = max;
//small = min;
while (small) { // While small is not 0
// Calculates GCD
rem = large % small;
large = small;
small = rem;
}
//gcd = large;
// printf("GCD(%d,%d)= %d", large, small, gcd);
}
gcd = large;
printf("GCD(%d,%d)= %d", large, small, gcd);
}