Reputation: 65
The following code is not outputting the desired result. It is only getting iterated through n, not y. Why and how to fix it?
int product(int m,int n){
int x,p;
while(m>=100){
while(n>=100){
printf("Value of m= %d and n=%d\n",m,n );
x=m*n;
p=palindrome(x);
if (p==0)
{
printf("These two numbers are %d and %d\n",m,n );
}
n--;
}
m--;
}
return 0;
}
Upvotes: 0
Views: 55
Reputation: 67820
Because `n' is not any more >= 100. So the external loop iterates but is never entering the internal after the first one.
The solution: Be careful!!!! - if you execute it online you will kill your browser :)
int product(int m,int n){
int x,p, savedn = n;
while(m>=100){
while(n>=100){
printf("Value of m= %d and n=%d\n",m,n );
x=m*n;
p=palindrome(x);
if (p==0)
{
printf("These two numbers are %d and %d\n",m,n );
}
n--;
}
m--;
n = savedn;
}
return 0;
}
Upvotes: 4