#include <stdio.h>
char checkpalindrome(int a)
{
int reminder;
int reverse = 0;
int result = 0;
int orgnum = a;
while(a)
{
reminder = a % 10;
a = a / 10;
reverse = (reverse * 10) + reminder;
//printf("%d\n",reverse);
}
if(reverse == orgnum)
{
printf("Valid Palindrome - %d = %d\n", reverse,orgnum);
result = 1;
}
else
{
printf("(reverse) %d != %d (original)\n", reverse,orgnum);
}
return result;
}
int main(void) {
// your code goes here
int x[3] = {121,15151,1022};
checkpalindrome(x[0]);
checkpalindrome(x[1]);
checkpalindrome(x[2]);
return 0;
}
char checkpalindrome(int a)
{
int reminder;
int reverse = 0;
int result = 0;
int orgnum = a;
while(a)
{
reminder = a % 10;
a = a / 10;
reverse = (reverse * 10) + reminder;
//printf("%d\n",reverse);
}
if(reverse == orgnum)
{
printf("Valid Palindrome - %d = %d\n", reverse,orgnum);
result = 1;
}
else
{
printf("(reverse) %d != %d (original)\n", reverse,orgnum);
}
return result;
}
int main(void) {
// your code goes here
int x[3] = {121,15151,1022};
checkpalindrome(x[0]);
checkpalindrome(x[1]);
checkpalindrome(x[2]);
return 0;
}
0 comments :
Post a Comment