Palindrome sayılar veya kelimeler düzden yazımı ile tersten yazımı aynı olanlardır.
Örnek : 12321, ey edip adanada pide ye
c# kodları
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
class Program
{
public static bool IsPalindrome(string value)
{
int min = 0;
int max = value.Length - 1;
while (true)
{
if (min > max)
{
return true;
}
char a = value[min];
char b = value[max];
if (char.ToLower(a) != char.ToLower(b))
{
return false;
}
min++;
max--;
}
}
static void Main()
{
string[] array ={"1551","12321","536754457635"};
foreach (string value in array)
{
Console.WriteLine("{0} = {1}", value, IsPalindrome(value));
}
}
}
Visual Basic Kodları
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Class Program
Public Shared Function IsPalindrome(ByVal value As String) As Boolean
Dim min As Integer = 0
Dim max As Integer = value.Length - 1
While True
If min > max Then
Return True
End If
Dim a As Char = value(min)
Dim b As Char = value(max)
If Char.ToLower(a) <> Char.ToLower(b) Then
Return False
End If
min += 1
max -= 1
End While
End Function
Private Shared Sub Main()
Dim array As String() = {"1551", "12321", "536754457635"}
For Each value As String In array
Console.WriteLine("{0} = {1}", value, IsPalindrome(value))
Next
End Sub
End Class