PALINDROME NUMBER

 

************************************************************************ 

W.A.P TO CHECK GIVEN NUMBER IS PALINDROME NUMBER OR NOT

************************************************************************ 

JAVA Program

import java.util.Scanner;
class demo {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the Number: " );
        int n= sc.nextInt();
        // System.out.println("\nEntered number is: "+n);
        int temp=0,x;
        int n2= n;
        while (n>0){
            x=n%10;
            n=n/10;
            temp= temp*10+x;
        }
        if (temp == n2)
        {
            System.out.println("Number is Panildrome " );
        }
        else{
            System.out.println("Number is not Panildrome " );
        }
    
    }}
    
        





   



  
Online compiler

Output:

Enter any Number :

161

Number is Palindrome

************************************************************************ 

C Program


#include<stdio.h>

void main() {
    int n,temp=0,n2,x;
    printf("Enter the Number: " );
    scanf("%d",&n);
    // printf("\nEntered number is: %d",n);
    n2=n;
    while (n>0){
        x=n%10;
        n=n/10;
        temp= temp*10+x;
    }
    if (temp == n2)
    {
       printf("Number is Panildrome " );
    }
    else{
        printf("Number is Not Panildrome " );
    }
    
}
Online Compiler 

 

************************************************************************ 

C++ Program

// Online C++ compiler to run C++ program online
#include <iostream>
int main() {
    int n,temp=0,n2,x;
    std::cout << "Enter the Number: ";
    std::cin>>n;
    //std::cout <<"\nEntered number is: "<<n
<<"\n";
    n2=n;
    while (n>0){
        x=n%10;
        n=n/10;
        temp= temp*10+x;
    }
    if (temp == n2)
    {
       std::cout<<"Number is Panildrome " ;
    }
    else{
        std::cout<<"Number is Not Panildrome " ;
    }
     return 0;
}
Online Compiler

************************************************************************ 

C# Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace HelloWorld
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}
 
 
Output:
Hello World!

************************************************************************ 

PHP Program

<?php

function palindrome($n){
    $num = $n;
    $sum = 0;
    while (floor($num)){
    $rem= $num %10;
    $num = $num /10;
    $sum = $sum * 10 + $rem;
    }
    return $sum;
}

$num = (int)readline('Enter the Number: ');
$n = palindrome($num);
if($num == $n){
echo "$num is a palindrome number";}
else{
echo "$num is not a palindrome number";}

?>

Online Compiler

Php is a serverside scripting language.

************************************************************************ 

JAVASCRIPT Program

  1. <html>  
  2. <head> <title> JavaScript Palindrome </title>  
  3. </head>  
  4. <body>  
  5.   
  6. <!-- Use JavaScript programming code to validate the Palindrome numbers or strings. -->  
  7. <script>        
  8.           
  9. function validatePalin(str) {  
  10.   
  11.     // get the total length of the words  
  12.     const len = string.length;  
  13.   
  14.     // Use for loop to divide the words into 2 half  
  15.     for (let i = 0; i < len / 2; i++) {  
  16.   
  17.         // validate the first and last characters are same  
  18.         if (string[i] !== string[len - 1 - i]) {  
  19.             alert( 'It is not a palindrome');  
  20.         }  
  21.     }  
  22.     alert( 'It is a palindrome');  
  23. }  
  24.   
  25. // accept the string or number from the prompt  
  26. const string = prompt('Enter a string or number: ');  
  27.   
  28. const value = validatePalin(string);  
  29.   
  30. console.log(value);  
  31. </script>  
  32.     </body>  
  33.         </html>  

Online Compiler

************************************************************************ 

PYTHON Program

 
temp=0
n=int(input("Enter the Number: "))
print("\nEntered number is: ",type(n))
n2=n
x=0
print("\nEntered number is: ",n2)

while n>0:
    #print(temp, n)
    x=n%10
    n=n//10
    temp= temp*10+x
#print(temp)
if (temp == n2):
    print("Number is Panildrome " )
else:
    print("Number is Not Panildrome " )
   

Online Compiler: 

************************************************************************  


Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

FIBONACCI SERIES