¡Tu solución está lista!
Nuestra ayuda de expertos desglosó tu problema en una solución confiable y fácil de entender.
Mira la respuestaMira la respuesta done loadingPregunta: Hacer un programa en c++ que dada frase de tamaño maximo N, determine si es un palíndromo o no.Usar cadenas.
Hacer un programa en c++ que dada frase de tamaño maximo N, determine si es un palíndromo o no.Usar cadenas.- Hay 2 pasos para resolver este problema.SoluciónPaso 1Mira la respuesta completaPaso 2
Programa para verificar si una oración ingresada (cadena) es palíndromo o no.
#include <iostream> #include <string> using namespace std; //function to check if the sentence is palndrom or not. bool isPalindrome(string sentence) { int l = sentence.length(); //find the length of the sentence. for (int i=0; i<l/2;i++) //for loop to check each character of the sentence { if (sentence[i] != sentence[l - i - 1]) { return false; } } return true; } int main() { const int MAX_SIZE = 100; char s[MAX_SIZE]; // character array decleration of maximum size N=100. cout << "Enter a sentence (up to 100 characters): "; cin.getline(s, MAX_SIZE); // read the sentence (including white space.) string st(s); // convert the character array s to string st. if (isPalindrome(st)) // if isPalndrom function return true, then { cout << "The sentence is palindrome.\n"; } else // else case, isPalndrom functon return false,then { cout << "The sentence is not palindrome.\n"; } return 0; }
Explanation:En este programa,
Primer...
DesbloqueaRespuestaDesbloquea
Estudia mejor, ¡ahora en español!
Entiende todos los problemas con explicaciones al instante y pasos fáciles de aprender de la mano de expertos reales.