Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Check whether a number is a palindrome or not

C# Sharp For Loop: Exercise-38 with Solution

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

Pictorial Presentation:

C# Sharp Exercises: Check whether a number is a palindrome or not

Sample Solution:

C# Sharp Code:

using System;  
public class Exercise38 
{  
    public static void Main()
{
    int num,r,sum=0,t;
	
	
	Console.Write("\n\n");
    Console.Write("Check whether a number is a palindrome or not:\n");
    Console.Write("------------------------------------------------");
    Console.Write("\n\n");  	

    Console.Write("Input a number: ");
    num = Convert.ToInt32(Console.ReadLine()); 	

    for(t=num;num!=0;num=num/10){
         r=num % 10;
         sum=sum*10+r;
    }
    if(t==sum)
         Console.Write("{0} is a palindrome number.\n",t);
    else
         Console.Write("{0} is not a palindrome number.\n",t);
	}	 
}

Sample Output:

Check whether a number is a palindrome or not:                                                              
------------------------------------------------                                                            
Input a number: 8                                                                                           
8 is a palindrome number. 

Flowchart:

Flowchart : Check whether a number is a palindrome or not

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to display the number in reverse order.
Next: Write a program in C# Sharp to find the number and sum of all integer between 100 and 200 which are divisible by 9.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.