answersLogoWhite

0


Best Answer

#include void main() { long int n; printf("ENTER A NUMBER: "); scanf("%ld",&n); int n1,mod; n1=n; int rev=0; while(n>0) { mod = n%10; rev = rev * 10 + mod; n = n / 10; } if (n1 == rev) printf("ENTERED NUMBER IS A PALINDROME\n"); else printf("ENTERED NUMBER NOT A PALINDROME\n"); }

User Avatar

Wiki User

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

Wiki User

7y ago

#include<stdio.h>

unsigned reverse (unsigned num) {

unsigned dgt, acc = 0;

while (num>0) { dgt = num%10; // determine last digit of num (remainder after division by 10)

rev = rev * 10; // left-shift the accumulator by 1 decimal digit

rev = rev + dgt; // add the digit

num = num / 10; // right-shift the number by 1 decimal digit

}

return acc; // the accumulator is the reverse of original number

}

bool is_palindrome (unsigned num) {

return num == reverse (num);

}

int main (void) {

unsigned num;

printf ("Enter a number greater than zero: ");

scanf ("%u\n", &num);

if (is_palindrome (num))

printf ("The number is a palindrome\n");

else

printf ("The number is not a palindrome\n");

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

//assume all files r included.

void main()

{

int n,n1,s=0,r;

cout<<"enter the number";cin>>n;

n1=n;

while(n)

{r=n%10;

s+=r*10;

n=n%10;

}

if (n1==s)

cout<<"no. is palindrome";

else cout<<endl<<"no. is not palindrome";

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

The easiest way to check if a number is a palindrome or not is to reverse the number and see if the value is the same as the original. To reverse a number in any base, use the following function:

unsigned int reverse(unsigned int num, unsigned int base=10)

{

unsigned int rev=0;

while( num )

{

rev*=base;

rev+=num%base;

num/=base;

}

return( rev );

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

3

#include

#include

main()

{

int n, num, digit, sum=0, rev=0;

printf("Input the number");

n=num;

do

{

digit=num%10;

sum+=digit;

rev=rev*10+digit;

num!=10;

}

while (num!=0);

printf("sum of the digits of the number=%d%d%d%d\n",sum);

printf("reverse of the number=%d%d%d%d%d%d%d\n", rev);

if(n==rev)

printf("the number is a palindrome\n");

else

print("the number is not a palindrome\n");

getch();

}

OUTPUT:

Run1:- Input the number 1234

sum of the digits of the number= 10

reverse of the number= 4321

the number is not a palindrome

Run2:- Input the number 1221

sum of the digits of the number= 6

reverse of the number= 1221

the number is a palindrome

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

/* Palindrome program by Shekhar */

#include<stdio.h>

#include<conio.h>

void main() {

int n, i = 0, k = 0;

clrscr();

printf( "Enter number: " );

scanf( "%d", &n );

int p = n;

while( n != 0 ) {

k = k * 10 + ( n % 10 );

n = n / 10;

i++;

}

if ( k==p ) {

printf( "number is palindrome\n" );

} else {

printf( "number is not palindrome\n" );

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Reverse the digits then test to see if the new number is the same as the original number. If it is, the number is a palindrome, otherwise it is not.

To reverse an unsigned integer (any base, default is 10):

unsigned rev (unsigned num, unsigned base=10)

{

unsigned r=0;

while (num)

{

r*=base;

r+=num%base;

num/=base;

}

return r;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Checking a number to see if it's palindromic in nature is a fun task. If the data were in arrays, all you would need to do is:

- calculate the halfway point in the array

- loop "count" from 0 to halfway-1 {

-- ch1 = arr[count]

-- ch2 = arr[array length - count - 1]

-- if ch1 and ch2 are not equal, return false

- }

- return true

If you're using an int, however, then to keep things simple (and probably faster) you may wish to break the integer down into each of its digits using the "%" modulus and "/" divide operators) while storing each of those digits in an array. Then pass that array into the function above. The bonus is that you know the maximum size of the array depends upon the size of the integer. If you're using a regular ol' "int", the maximum value's going to be about 2 billion, so 10 digits are going to be the max. Negative integers won't be palindromic because of the prefixed "-".

The author will leave it to you, the intrepid programmer, to write the code. Enjoy!

This answer is:
User Avatar

User Avatar

Nafis Abir

Lvl 2
3y ago

#include

#include

main()

{

int n, num, digit, sum=0, rev=0;

printf("Input the number");

n=num;

do

{

digit=num%10;

sum+=digit;

rev=rev*10+digit;

num!=10;

}

while (num!=0);

printf("sum of the digits of the number=%d%d%d%d\n",sum);

printf("reverse of the number=%d%d%d%d%d%d%d\n", rev);

if(n==rev)

printf("the number is a palindrome\n");

else

print("the number is not a palindrome\n");

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

just use the modulo (%) fcn to get the palindrome of the number.

the algorithm is for you to think so you'll know.

it is just easy. try it!

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a C program to check a Given Number Whether is it Palindrome or Not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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;


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(); }


How do you generate palindrome number between the given range?

The generation of palindromic numbers within a given range is best done with a computer program. Space it limited so an example of program code cannot be shown here, but the Codecast website gives full guidance.


Write a c program that reverse a given integer number and check whether the number is palindrome or not?

#include &lt;stdio.h&gt; #include &lt;string.h&gt; #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 -&gt;palindrome, flag =1 -&gt;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 &lt;stdio.h&gt; #include &lt;string.h&gt; #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 -&gt;palindrome, flag =1 -&gt;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; }

Related questions

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;


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(); }


How can you generate a palindrome from a given number?

You write the number and then follow it with the digits in reverse order.


Could you write a assembly language program in tasm To check whether a given number present in a sequence of given memory location containing the string to be checked in 8086?

8086 assembly language program to check wether given number is perfect or not


How do you generate palindrome number between the given range?

The generation of palindromic numbers within a given range is best done with a computer program. Space it limited so an example of program code cannot be shown here, but the Codecast website gives full guidance.


Lab manual in mca 1st sem from ignou?

write a program in C to check whether a given number is apalindrome or not


Write a c program that reverse a given integer number and check whether the number is palindrome or not?

#include &lt;stdio.h&gt; #include &lt;string.h&gt; #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 -&gt;palindrome, flag =1 -&gt;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 &lt;stdio.h&gt; #include &lt;string.h&gt; #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 -&gt;palindrome, flag =1 -&gt;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; }


How do you determine if a given string is palindrome or not?

Reverse the string and compare it to the original. If they match, then it is a palindrome.


To check whether the given number is an Avogadro number or not?

45


Write a c program using while loop to accept a number check and display message whether number is perfect or not?

The program is here guys.......... //Finding whether the given number is perfect or not //Starts here #include&lt;stdio.h&gt; void main() { int i=1,temp=0,number; scanf("%d",&amp;number); while(i&lt;=number/2){ if(number%i==0) temp+=i; i++; } if(temp==number) printf("Its a perfect number"); else printf("Its not a perfect number"); } //ends here


What is the palindrome for the kind of welcome given by a mayor?

civic