So I have a task to find 75 palindromes which squares are also palindromes. I have only the part where it finds palindromes and I need some help/explanation on how to do the squaring of each found palindrome and outputing only 75 of those whose squares are palindromes..
The simplyer code is, the better :D
Solved it thanks to:
#include<iostream>
usingnamespace std;
int yraPal(int n)
{
int atv = 0;
for (int i = n; i > 0; i /= 10)
atv = atv*10 + i%10;
return (n==atv);
}
void skaicPal()
{int count=0;
for (unsignedlongint i = 0; ; i++)
if (yraPal(i) && yraPal(i*i))//simple just check if the pallindrome of square is true or not!
{
cout << i << endl;
count++;
if(count==75)//for 75 int numbers only
break;
}
}
int main()
{
skaicPal();//removed the min max... was a bit constraining
return 0;//also square of 0 and 1 and 2 and so on is also palindrome
}
//only 21 outputs...
I'll leave the number repetition part to you :)
PS: I was doubtful if zero was considered a palindrome... googled and found that is is a palindrome....
#include<iostream>
usingnamespace std;
int yraPal(int n)
{
int atv = 0;
for (int i = n; i > 0; i /= 10)
atv = atv*10 + i%10;
return (n==atv);
}
void skaicPal()
{int count=0;
for (unsignedlong i = 0; ; i++)
if (yraPal(i) && yraPal(i*i))//simple just check if the pallindrome of square is true or not!
{
cout << count << ". " << i << " (" << i * i << ")" << endl;
if(++count==75) //for 75 int numbers only
break;
}
}
int main()
{
skaicPal();//removed the min max... was a bit constraining
return 0;//also square of 0 and 1 and 2 and so on is also palindrome
}