Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 3 Detector de palíndromos
- Implemente código C para testar se uma cadeia de caracteres (string) é um palíndromo. Um palíndromo
- é uma palavra idêntica quando lida de trás para frente, como "arara", "radar" e "reviver".
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int palindromos (char word[]) {
- int i=0, j;
- j = strlen(word) - 1;
- while (i <= j) {
- if (word[i] != word[j]) {
- return 0;
- }
- i++;
- j--;
- }
- return 1;
- }
- void main(){
- char palavra[100];
- printf ("Digite uma palavra para saber se eh um palindromo:\n");
- gets (palavra);
- if (palindromos(palavra)){
- printf ("Eh um palindromo\n");
- }
- else printf ("Nao eh um palindromo\n");
- system ("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement