answersLogoWhite

0


Best Answer

#include <stdio.h>

#include <string.h>

#define N 100

#define PALINDROME 0

#define NONPALINDROME 1

/*Program that tells you whether what you enter is a palindrome or not*/

char pal[N]; //input line

int i; //counter

int k; //counter

int tag;

int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/

int main()

{

printf("Enter something: \n");

scanf("%s", pal);

tag = strlen(pal); /*determine length of string*/

/* pointer running from the beginning and the end simultaneously

looking for two characters that don't match */

/* initially assumed that string IS a palindrome */

/* the following for loop looks for inequality and flags the string as

a non palindrome the moment two characters don't match */

for (i=0,k=tag-1; i=0; i++,k--) {

if(pal[i] != pal[k]) {

flag=NONPALINDROME;

break;

}

}

if(flag == PALINDROME) {

printf("This is a palindrome\n");

}

else {

printf("This is NOT a palindrome\n");

}

return 0;

}

#include <stdio.h>

#include <string.h>

#define N 100

#define PALINDROME 0

#define NONPALINDROME 1

/*Program that tells you whether what you enter is a palindrome or not*/

char pal[N]; //input line

int i; //counter

int k; //counter

int tag;

int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/

int main()

{

printf("Enter something: \n");

scanf("%s", pal);

tag = strlen(pal); /*determine length of string*/

/* pointer running from the beginning and the end simultaneously

looking for two characters that don't match */

/* initially assumed that string IS a palindrome */

/* the following for loop looks for inequality and flags the string as

a non palindrome the moment two characters don't match */

for (i=0,k=tag-1; i=0; i++,k--) {

if(pal[i] != pal[k]) {

flag=NONPALINDROME;

break;

}

}

if(flag == PALINDROME) {

printf("This is a palindrome\n");

}

else {

printf("This is NOT a palindrome\n");

}

return 0;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Program:

#include
#include
void main()
{
long int n,m,rev=0,r;
clrscr();
printf("\nEnter the number:");
scanf("%ld",&n);
m=n;
while(n>0)
{
r=n%10;
rev=rev*10+r;
n=n/10;
}
if(rev==m)
printf("Palindrome");
else
printf("Not Palindrome");
getch();
}

output:
Enter the number:123321
Palindrome
Enter the number:12420
Not Palindrome

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program that reverse a given integer number and check whether the number is palindrome or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


C program to check whether the number and its reverse are same or not?

#include &lt;stdio.h&gt; #include&lt;conio.h&gt; void main () { int a,r,n,sum=0; clrscr(); printf("enter the number"); scanf("%d",&amp; n); c=n while (n!=0) { a=n%10; n=n/10; sum=sum*a+a } printf("the reverse is %d \n",sum); if(c==sum) printf("\n the given number is palindrome"); else printf("\n the given number is not a palindrome"); getch(); }


Write a program using method plainto check whether a string is a palindrome or not A palindrome is a string that reads the same from left to right and vice-versa?

Palindrome number is a number like 121 which remains the same when its digits are reversed. To find this number in a simple java program, just follow the below way. sum = 0; while(n&gt;0) { r=n % 10; sum=concat(r); n=n / 10; } print r;


What is an example program in Bluej whether a number is a palindrome or not?

class test { public static void main(int num) { int num2=num; int rnum=0; while (num2&gt;0) { int q=num2/10; int dig=num2%10; rnum = rnum*10+dig; num2=q; } if (rnum==num) System.out.println("Palindrome number"); else System.out.println("Not a Palindrome number"); } }


Write a PHP program to check whether the number is palindrome or not?

This program only suits PHP. If you want a proper one try C program for it available on web &lt;body&gt; &lt;?php if(isset($_POST['submit'])) { $text = $_POST['text']; $string = mysql_real_escape_string($text); $invert = strrev($string); if($string == $invert) { echo "&lt;br&gt;Given number is a palindrome!!"; } else { echo "&lt;br&gt;Given number is not a palindrome!!"; } } ?&gt; &lt;form method="post"&gt; &lt;input type="text" name="text" id="text" /&gt; &lt;input type="submit" name="submit" value="Submit" id="submit" onclick="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" /&gt; &lt;/form&gt; &lt;/body&gt;

Related questions

Write a PHP program to check whether the string is palindrome or not?

You can do this: &lt;?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }


What are the explanation steps for palindrome program?

If you want to check whether a string is a palindrome, you can reverse the string (for example, the Java class StringBuffer has a reverse() method), and then compare whether the two strings - the original string and the reverted string - are equal. Alternately, you could write a loop that checks whether the first character of the string is equal to the last one, the second is equal to the second-last one, etc.; that is, you have a counter variable (in a "for" loop) that goes from zero to length - 1 (call it "i"), and compare character #i with character #(length-i-1) inside the loop.


How do you write a simple program in c to check whether a number is a palindrome or not?

unsigned reverse (unsigned n) { unsigned r = 0; while (n) { r *= 10; r += (n%10); n /= 10; } return r; } bool is_palindrome (unsigned n) { return n == reverse (n); } int main () { unsigned num; printf ("Enter a number: "); scanf ("%d", num); if (is_palindrome (num)) printf ("%d is a palindrome\n"); else printf ("%d is not a palindrome\n"); return 0; }


How do you write a program in C to check whether a word is a palindrome or not?

It is a simple program. i think u may understand it :#include#include#includevoid main(){char s[10]=answers.com;char x[10];int a;clrscr();strcpy(x,s);strrev(s);a=strcmp(s,x);if(a==0){printf("the entered string is palindrome");}else{printf("the entered string is not palindrome");}output:given string is not palindrome


Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


Which of these is a palindrome 56546 or 56456 or 45654?

45654 is the palindrome because it reads the same whether forward or backward.


Is 4 a palindrome?

The number '4' can be considered a palindrome because it is read the same whether forward or backward. It can become another palindrome when it is considered as 2x2.


C program to check whether the number and its reverse are same or not?

#include &lt;stdio.h&gt; #include&lt;conio.h&gt; void main () { int a,r,n,sum=0; clrscr(); printf("enter the number"); scanf("%d",&amp; n); c=n while (n!=0) { a=n%10; n=n/10; sum=sum*a+a } printf("the reverse is %d \n",sum); if(c==sum) printf("\n the given number is palindrome"); else printf("\n the given number is not a palindrome"); getch(); }


C program to test whether the integer is palindrome or not?

#include &lt;math.h&gt; // this will test if a base 10 integer is a palindrome int is_palindrome_10(const unsigned int n) { if( n &lt; 10 ) return 1; unsigned int i, num_digits, num_digits_2; num_digits = ((unsigned int) log10(n) + 1); num_digits_2 = num_digits/2; // sorry the if statement is so ugly. looks neater in my editor :\ for(i = 0; i &lt; num_digits_2; ++i) if( ((unsigned int) ( n/pow(10, num_digits - i - 1) ) % 10) != ((unsigned int) ( n/pow(10, i) ) % 10) ) return 0; return 1; }


Why isn't palindrome spelled the same way backwards and forwards?

Because palindrome is not a palindrome. However, a dromedary is the same thing whether it is going backwards or forwards.


What requires a binding site called palindrome?

A palindrome indicates a statement that has the same meaning, whether read backward or forward.


Write a program using method plainto check whether a string is a palindrome or not A palindrome is a string that reads the same from left to right and vice-versa?

Palindrome number is a number like 121 which remains the same when its digits are reversed. To find this number in a simple java program, just follow the below way. sum = 0; while(n&gt;0) { r=n % 10; sum=concat(r); n=n / 10; } print r;