#include<stdio.h>
int f,b;
int x=0;
int m=502;
int n=3;
int r=1;
int main()
{
printf("in main\n");
int loop=0;
while(1)
{
printf("in while %d %d %d\n",m,n,r);
printf("if(m>n) %d\n\n",m>n);
if(m>n)
{
f=m/n;
b=f*n;
r=m-b;
printf("m>n 1\n");
}
printf("if(m<n) %d\n\n",m<n);
if(m<n)
{
f=n/m;
b=f*m;
r=n-b;
printf("m<n 2\n");
}
printf("if(r==0) %d\n\n",r);
if(r==0)
{
printf("m=%i n=%i b=%i f=%i\n",m,n,b,f);
return(1);
}
printf("if(m>n && m>r) %d\n\n",m>n && m>r);
if(m>n && m>r)
{
printf("m>n && m>r 4\n");
m=r;
}
printf("if(n>m && n>r) %d\n\n",n>m && n>r);
if(n>m && n>r)
{
printf("n>m && n>r 5\n");
n=r;
}
if(loop++ == 10)
break;
}
}
Your loop was working fine, but all the conditional if statements are returning 0,which is why your printf statements in the condition never executed, after the first iteration of the loop.
I did not try to understand whatever you are trying to achieve. But, I reckon, that you are new to programming.
Word of Advice
Always, use printf statements, when ever you are having trouble with loops, as I did. Looking at the loop variables or any other variables that are undergoing change will help track the execution flow of the loop better.
7
solved simple loop is not working properly