w3resource
C# Sharp Programming Exercises

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?



New Content: Composer: Dependency manager for PHP, R Programming