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


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class csharpExercise
  7. {
  8. static void Main(string[] args)
  9. {
  10. int num, i, rev;
  11.  
  12. // Reading a number from user
  13. Console.Write("Enter any number: ");
  14. num = Convert.ToInt32(Console.ReadLine());
  15.  
  16. rev = num;
  17. for (i = 0; num > 0; num = num / 10)
  18. {
  19. i = i * 10;
  20. i = i + (num % 10);
  21. }
  22.  
  23. //Checking if reverse number is equal to original num or not.
  24. if (rev == i)
  25. Console.WriteLine(rev+" is a Palindrome Number.");
  26. else
  27. Console.WriteLine(rev + " is not a Palindrome Number.");
  28.  
  29.  
  30. Console.ReadLine();
  31. }
  32. }

Result

C# language techstudy

     





Related Topics




Popular Posts