Problem In for Loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
using namespace std;
int main()
{
	int mul,res=0,k,j;
	for(int i=1;i<5;i++)
	{
		for(j=1;j<5;j++)
		{
			mul=i*j;
                        cout<<mul<<",";
			if(mul>0)
			{
				k=mul%10;
				res=(res*10)+k;
				mul=mul/10;
				if((res>10) && (res==mul))
					cout<<"\nres:"<<res;
			}
		}
		cout<<"\n";
	}
	return 0;
}


hi everybody
this is the code i am writing to get the palindrome of product of numbers.
But while excuting the if block is not working what i have written in the for loop. why this happening can anybody help?????
Last edited on
@sirja: I am using Turbo C++ v4.5
according to me... you should try adding '.h' to 'iostream' and write it as 'iostream.h'
and then removing the second line i.e. 'using namespace std'...
it worked out for me... just give it a try...
Step through the code either in your head or using a debugger, watching the variables mul and res. You will see that res is never greater than 10 when res is equal to mul.


according to me
only according to you though. "iostream.h" is wrong and has been for well over 10 years already.
Topic archived. No new replies allowed.