Created
December 21, 2017 02:01
-
-
Save parzibyte/cf06316e801eede3d9b1892627f6be60 to your computer and use it in GitHub Desktop.
Comprobar si una palabra es palíndroma (o como se escriba) en C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace App | |
{ | |
class Programa | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Introduce una palabra y te diré si es palíndroma :) "); | |
String palabra = Console.ReadLine(); | |
if(esPalindroma(palabra)) Console.WriteLine("Es palíndroma"); | |
else Console.WriteLine("NO es palíndroma"); | |
} | |
static Boolean esPalindroma(String cadena){ | |
Console.WriteLine("Función llamada con => " + cadena); | |
if(cadena.Length < 2) return true; | |
Console.WriteLine("Vamos a comparar => " + cadena[0]); | |
Console.WriteLine("Con => " + cadena[cadena.Length - 1]); | |
if(cadena[0] == cadena[cadena.Length - 1]) return esPalindroma(cadena.Substring(1, cadena.Length - 2)); | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment