Guião laboratorial n.º 0 – exercício 11

“Desenvolva uma função que verifique se uma string recebida como argumento armazena uma capicua. A função devolve 1 se isso se verificar ou 0 no caso contrário.”
nota: LINK

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TAM 100

int capicua(char s[TAM]){
int i,conta=0, e=0;
conta=strlen(s);

for(i = 0; i<conta; i++, conta--){
  if(s[i] != '\0'){
    if(s[i] == s[conta-1])
    {
      printf("\n%c - %c", s[i],s[conta-1]);
    }else{
    e++;
    }
  }
}
if(e>0){
    return 0;
  }else{
    return 1;
  }

}

int main ()
{
    char texto[TAM]="1467641";
    if(capicua(texto)){
        printf("\ntemos capicua!");
    }else{
        printf("\nnao temos capicua!");
    }
return 0;
}


Tags :

0 thoughts on “Guião laboratorial n.º 0 – exercício 11”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.