Thursday, 8 November 2018

how to find palindrome number in c,c++ and java

PALINDROME NUMBER:

Palindrome number is number remains the same after reversing the given number

Like 12312, for example, it is "symmetrical". The term palindromic is derived from palindrome, which refers to a word whose spelling is unchanged when its letters are reversed.

Ex:

aba after reverse the given word they will unchanged, 181, 191, 202

PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME NUMBER OR NOT IN C 



#include <stdio.h>

int main()
{



   int n, rev = 0, tem;
 


   printf("Enter a Number To Check Palindrome number\n");
   scanf("%d", &n);

   tem = n;

   while (tem != 0)
   {
      rev= rev * 10;


      rev= rev + tem%10; //first seperate last value by modulus of 10 ex:212%10=2


      tem = tem/10; seperate without last value so divede by 10 ex:212/10=21
   }

   if (n == rev) old vaue is same as new value then number is palindrome


      printf("%d is a palindrome number.\n", n);


   else


      printf("%d isn't a palindrome number.\n", n);

   return 0;
}

OUTPUT:
PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME NUMBER OR NOT IN C ++


#include <iostream>

using namespace std;
int main()
{

   int n, rev = 0, tem;
 

  cout<<"Enter a Number To Check Palindrome number\n"
 cin>>n;

   tem = n;

   while (tem != 0)
   {
      rev= rev * 10;


      rev= rev + tem%10;


      tem = tem/10;
   }

   if (n == rev)


    cout<<"is palindrome number";


   else


     cout<<" isn't a palindrome number"

   return 0;
}









PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME NUMBER OR NOT IN JAVA



import java.util.*;

class Palindrome    //java file name is same as class name

{

public static void main(String s[])

{Scanner in=new Scanner(System.in); //create a scanner class object to read the input from user

   int n, rev = 0, tem;
 

System.out.println("Enter a Number To Check Palindrome number\n")

 n=in.nextInt();

//read the integer value for float use in.nextFloat(); and for String use in.next()

   tem = n;

   while (tem != 0)
   {
      rev= rev * 10;


      rev= rev + tem%10;


      tem = tem/10;
   }

   if (n == rev)

System.out.println("is palindrome number");

   else

System.out.println("isn't a palindrome number");
}

}


No comments:

Post a Comment