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 " );
}
}}
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!");
        }
    }
}  
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";}
?>
Php is a serverside scripting language.
************************************************************************
JAVASCRIPT Program 
- <html>
- <head> <title> JavaScript Palindrome </title>
- </head>
- <body>
- <!-- Use JavaScript programming code to validate the Palindrome numbers or strings. -->
- <script>
- function validatePalin(str) {
- // get the total length of the words
- const len = string.length;
- // Use for loop to divide the words into 2 half
- for (let i = 0; i < len / 2; i++) {
- // validate the first and last characters are same
- if (string[i] !== string[len - 1 - i]) {
- alert( 'It is not a palindrome');
- }
- }
- alert( 'It is a palindrome');
- }
- // accept the string or number from the prompt
- const string = prompt('Enter a string or number: ');
- const value = validatePalin(string);
- console.log(value);
- </script>
- </body>
-         </html>   
************************************************************************  
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 " )
    
************************************************************************   
Comments
Post a Comment