0% found this document useful (0 votes)
68 views1 page

Palindrome

This C# program checks if a number is a palindrome by reversing the number and comparing it to the original. The user inputs a number which is stored as n. n is used to calculate the reversed number rev by extracting the remainder of n divided by 10 at each step of a while loop. If the original number p is equal to the reversed number rev, the number is output as a palindrome, otherwise it is not a palindrome.

Uploaded by

digantasahariah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views1 page

Palindrome

This C# program checks if a number is a palindrome by reversing the number and comparing it to the original. The user inputs a number which is stored as n. n is used to calculate the reversed number rev by extracting the remainder of n divided by 10 at each step of a while loop. If the original number p is equal to the reversed number rev, the number is output as a palindrome, otherwise it is not a palindrome.

Uploaded by

digantasahariah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

1. Write a program to check whether a number is palindrome or not in C#.

using System;
using System.Collections.Generic;
using System.Text;

namespace LABPROGRAMS
{
class PALINDROME1
{
public static void Main(string[] args)
{

int n, rev = 0, rem, p;


Console.WriteLine("PROGRAM TO CHECK GIVEN INPUT NO IS
PALINDROME OR NOT");

Console.WriteLine("\n\nEnter n value");
n = int.Parse(Console.ReadLine());
p = n;

while (n > 0)
{
rem = n % 10;
n = n / 10;
rev = (rev * 10) + rem;
}

if (p == rev)
Console.WriteLine("The value {0} is palindrome", rev);
else
Console.WriteLine("The value {0} is not palindrome", rev);
Console.ReadLine();
}

You might also like