Home > Back-end >  C two layers of nested loop and outer loop only once
C two layers of nested loop and outer loop only once

Time:09-29

The procedure is as follows,
Part of the loop and outer loop will only conduct a ended, the inner loop can run normally, then particularly bizarre if I comment out the line output added can back to normal again, what is???????

#include
Int main ()
{
Int the GCD (int a0, int b0);
int num;
Int Max=0, max0=0;
Int I=1, j;
Int g;
The scanf (" % d ", & amp; Num);
for(i=1; i{
For (j=I; j{/* printf (" \ n \ n % d % d ", I, j); */
G=GCD (I, j);
Max0=(I * j)/g - g;
If (max}
}
Printf (" % d ", Max);
return 0;
}

Int the GCD (int a0, int b0)
{int temp.
While (temp!=0)
{
Temp=a0 % b0;
A0=b0;
B0=temp;
}
Return a nought;
}

CodePudding user response:

Int the GCD (int a0, int b0)
{int temp.==="" temp no initialization here, don't know what value is
While (temp!=0)=="" causes the loop to judge problems solution is to give it an a temp to the initial value is not equal to 0
{
Temp=a0 % b0;
A0=b0;
B0=temp;
}
Return a nought;
}

CodePudding user response:

 int the GCD (int a0, int b0) 
{
//int temp.
Int temp=1;
While (temp!=0)
{
Temp=a0 % b0;
A0=b0;
B0=temp;
}

Return a nought;
}

For your reference ~

Problem may not on the loop, but the GCD function not initialize the temp,
To the following:
 int the GCD (int a0, int b0) 
{
int temp;
If # 1
Do {
Temp=a0 % b0;
A0=b0;
B0=temp;
} while (temp);

# the else
While (temp!=0)
{
Temp=a0 % b0;
A0=b0;
B0=temp;
}
# endif
Return a nought;
}

CodePudding user response:

But why do I add the output can be amazing normal execution

CodePudding user response:

reference 1st floor CHXCHXKKK response:
int the GCD (int a0, int b0)
{int temp.==="" temp no initialization here, don't know what value is
While (temp!=0)=="" causes the loop to judge problems solution is to give it an a temp to the initial value is not equal to 0
{
Temp=a0 % b0;
A0=b0;
B0=temp;
}
Return a nought;
}

But why do I add the special magic on the output can be normal operation of the
  • Related