Fandom

Scratchpad

PLE:Unidad4Ejercicio11

219,356pages on
this wiki
Add New Page
Discuss this page0 Share
/*
Programa:         Unidad4Ejercicio11.cpp
Fecha:            01/12/2006
Descripción:      Lee una cadena y nos dice si es palíndromo.

*/
#include <iostream>
#include <conio>
#include <stdlib>
#include <ctype>
using namespace std;

void copiaCadenaSinEspacios(char *cadDestino, const char *cadFuente);
bool esPalindromo(char *c);

void main()
{
      char cad1[80], cad2[80];

      cout << "Introduzca una cadena ";
      cin.getline(cad1,80);
      cout << endl;

      copiaCadenaSinEspacios(cad2, cad1);

      cout << "La cadena original es : " << cad1 << endl;
      cout << "La cadena sin espacios es : " << cad2 << endl;

      if(esPalindromo(cad2))
            cout << "Es palindromo";
      else
            cout << "No es palindromo";

      cin.ignore();
      cin.get();
}

void copiaCadenaSinEspacios(char *cadDestino, const char *cadFuente)
{
      unsigned int i, j;
      for(i = 0, j = 0 ;i <= strlen(cadFuente); i++)
      {
            if(cadFuente[i] != ' ')
            {
                  cadDestino[j] = cadFuente[i];
                  j++;
            }
      }
}

bool esPalindromo(char *c)
{
      unsigned int i,j;
      bool p = true;
      for(i = 0, j = strlen(c) - 1; i < strlen(c)/2 && p; i++, j--)
      {
            if(c[i] != c[j])
                  p = false;
      }
      return p;
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random wikia