English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

ex
1. 19891
2.24842
3.12321
4.44444

2006-11-10 05:59:48 · 3 answers · asked by Mike Love 1 in Computers & Internet Programming & Design

in python script.

2006-11-10 07:52:05 · update #1

3 answers

#include
void main()
{
long num, n, rev=0, digit;
printf("enter a number : ");
scanf("%ld",&num);
n= num;
while(n!=0)
{
digit = n%10;
rev=rev*10+digit;
}
if(rev==num)
printf("Palindrome");
else
printf("Not a palindrome");
}

2006-11-10 06:14:43 · answer #1 · answered by smartsuman2k1 2 · 1 0

/*
* This program reads lines from standard input one at a time until
* the word "quit" appears on its own line. For each line, it decides
* whether or not the string is a palindrome.
*/

#include
#include
#include

int main(void)
{
char string[40];
char forwards[40];
char backwards[40];
char *pc;
int length, index;

while(1)
{
/* Read next line, make sure not end-of-file. */
if(gets(string) == NULL)
{
printf("Bug! End-of-file encountered!\n");
return 1;
}

/* Check if line equals "quit". */
if (strcmp(string, "quit") == 0)
{
printf("Thank you for using the program. Good-bye!\n");
break;
}

length = strlen(string);

/* Copy letters (converted to lower-case) from given string
* into array "forwards" in forwards order. */
index = 0;
for (pc = string; pc < string + length; pc++)
{
if (isalpha(*pc))
forwards[index++] = tolower(*pc);
}
forwards[index] = '\0';

/* Copy letters (converted to lower-case) from given string
* into array "backwards" in backwards order. */
index = 0;
for (pc = string + length - 1; pc >= string; pc--)
{
if (isalpha(*pc))
backwards[index++] = tolower(*pc);
}
backwards[index] = '\0';

/* Check if "forwards" and "backwards" arrays are identical. */
if (strcmp(forwards, backwards) == 0)
printf("That is a palindrome!\n");
else
printf("That is NOT a palindrome!\n");
}

return 0;
}

2006-11-10 14:01:19 · answer #2 · answered by god knows and sees else Yahoo 6 · 0 0

If your are using array to store these numbers you can test like this

main()
{
int a[5]={4,4,4,4,4};
boolean flag = false;

for(int i=0,j=4(array size-1);i!=j;i++,j--)
{
if(a[i]==a[j])
flag = true;
else
flag = false;
}

if(flag == true)
pirnt("it is palindrome");
}

2006-11-10 14:15:37 · answer #3 · answered by Sarat 1 · 0 0

fedest.com, questions and answers