Write a C# Sharp program to check whether a given integer is a palindrome integer or not. Return true if the number is palindrome otherwise return false
- برمجة سي شارب
- برمجة
- 2021-05-31
- ahmadghneem
الأجوبة
using System;
namespace exercises {
class Program {
static void Main(string[] args) {
int n;
n = 123456;
Console.WriteLine("Original integer value: " + n);
Console.WriteLine("Check the said number is a palindrome number or not:");
Console.WriteLine(test_is_Palindrome(n));
n = 16461;
Console.WriteLine("Original integer value: " + n);
Console.WriteLine("Check the said number is a palindrome number or not:");
Console.WriteLine(test_is_Palindrome(n));
n = -121;
Console.WriteLine("Original integer value: " + n);
Console.WriteLine("Check the said number is a palindrome number or not:");
Console.WriteLine(test_is_Palindrome(n));
}
public static bool test_is_Palindrome(int a)
{
if (a < 0) { return false; }
if (a < 10) { return true; }
var temp = a;
var b = 0;
var digit = 0;
while (temp != 0)
{
digit = temp % 10;
b = b * 10 + digit;
temp /= 10;
}
return a == b;
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال