#include "stdafx.h"
#include %26lt;iostream%26gt;
#include %26lt;cmath%26gt;
using namespace std;
bool isNumPalindrome (int num);
int main()
{
//I dont know what to input here
return 0;
}
bool isNumPalindrome (int num)
{
double pwr = 0;
//Step 1
if (num %26lt; 10)
return true;
//Step 2
else
{
// Step 2.a
while (num / static_cast%26lt;int%26gt;(pow(10,pwr)) %26gt;= 10)
pwr++;
while (num %26gt;=10) //Step 2.b
{
int tenTopwr = static_cast%26lt;int%26gt; (pow(10,pwr));
if ((num / tenTopwr) != (num % 10))
return false; //Step 2.b.1
else //Step 2.b.2
{
num = num % tenTopwr; //Step 2.b.2.1
num = num /10; //Step 2.b.2.1
pwr = pwr -2; //Step 2.b.2.2
}
}//end while
return true;
}//end else
return 0;
}
I dont know how to call the isnumpalindome in the int main()
C++ Palindrome Number?
int main()
{
for (int i=0; i%26lt;40000000; ++i)
if (isNumPalindrome(i)) // called here
printf("This is a Palindrome\n");
else
printf("This is not a Palindrome\n");
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment