palindrome program in c
Answers
Answered by
5
#include <stdio.h>
int main() {
int n, reverse = 0, temp;
printf("Enter a number to check if it is a palindrome or not\n");
scanf("%d",&n);
temp = n;
while( temp != 0 ) {
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if ( n == reverse ) printf("%d is a palindrome number.\n", n);
else printf("%d is not a palindrome number.\n", n);
return 0;
}//check if that hlps :)
int main() {
int n, reverse = 0, temp;
printf("Enter a number to check if it is a palindrome or not\n");
scanf("%d",&n);
temp = n;
while( temp != 0 ) {
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if ( n == reverse ) printf("%d is a palindrome number.\n", n);
else printf("%d is not a palindrome number.\n", n);
return 0;
}//check if that hlps :)
Answered by
4
Hey friend,
Now, the programming which i have learnt uses BufferedReader (some use ScannerClass)... so I will give you the program Using BufferedReader
Palindrome Number is a number which when reversed is the same number
Example :- 121... when u reverse 121 you get 121
import java.io.*
class Palindrome
{
public static void main () throws IOException
{
System.out.println("Enter a number");
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
int n = Integer.parseInt (br.readLine()); //to read number
int rev = 0; // to find reverse of number
int rem = 0; // to find remainder
int n1=n; //to store value of n
while (n>0)
{
rem = n%10;
rev = rem*10 + rev
n = n/10;
}
if (rev==n1)
System.out.println("Yes! it is a palindrome number");
else
System.out.println("No! it is not a palindrome number");
}
}
-------------------------------------------------------------------------
Now,
Palindrome word is a word which is same when reversed
Example :- WOW which is same when reversed WOW
import java.io.*
class Palindrome
{
public static void main () throws IOException
{
System.out.println("Enter a number");
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
String S=br.readLine(); // to read string
String rev=""; // to find reverse of word
int len = S.length(); //to find length of string
int i = 0; //to get index position
for (i<len ; i>=0 ; i--)
{
char c= S.charAt(i) ; //to get the character
rev = rev + c;
}
if (S.equals(rev)==true)
System.out.println("Yes! It is a palindrome word");
else
System.out.println("No! it is not a palindrome word");
}
}
Hope it helps!
Now, the programming which i have learnt uses BufferedReader (some use ScannerClass)... so I will give you the program Using BufferedReader
Palindrome Number is a number which when reversed is the same number
Example :- 121... when u reverse 121 you get 121
import java.io.*
class Palindrome
{
public static void main () throws IOException
{
System.out.println("Enter a number");
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
int n = Integer.parseInt (br.readLine()); //to read number
int rev = 0; // to find reverse of number
int rem = 0; // to find remainder
int n1=n; //to store value of n
while (n>0)
{
rem = n%10;
rev = rem*10 + rev
n = n/10;
}
if (rev==n1)
System.out.println("Yes! it is a palindrome number");
else
System.out.println("No! it is not a palindrome number");
}
}
-------------------------------------------------------------------------
Now,
Palindrome word is a word which is same when reversed
Example :- WOW which is same when reversed WOW
import java.io.*
class Palindrome
{
public static void main () throws IOException
{
System.out.println("Enter a number");
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
String S=br.readLine(); // to read string
String rev=""; // to find reverse of word
int len = S.length(); //to find length of string
int i = 0; //to get index position
for (i<len ; i>=0 ; i--)
{
char c= S.charAt(i) ; //to get the character
rev = rev + c;
}
if (S.equals(rev)==true)
System.out.println("Yes! It is a palindrome word");
else
System.out.println("No! it is not a palindrome word");
}
}
Hope it helps!
ABHAYSTAR:
Nice answer !
Similar questions
Math,
8 months ago
Hindi,
8 months ago
Math,
1 year ago
Social Sciences,
1 year ago
Math,
1 year ago