Home arrow Programmazione arrow Listati arrow Frasi Palindrome

welcome

powered by Linux and mysql

/home/emdel/img


-=Calendario=-

 ott   Novembre 2009   dic

DLMMGVS
  1  2  3  4  5  6  7
  8  91011121314
15161718192021
22232425262728
2930 
Blog Behavioral Synthesis

Quat Menu

Amministratore
Grafica
Programmazione
«Random»
Linux
Internet

Commenti&Chat

Frasi Palindrome PDF Stampa E-mail
Scritto da Administrator   
giovedě 07 dicembre 2006
#include <stdio.h>
#define DIM 256
int main()
{
   char frase[DIM+1];
   int lunghezza;
   int c,d;
   int ok=1;
   printf ("\t###############################\n");
   printf ("\t#Programma realizzato da Emdel          #\n");
   printf ("\t###############################\n\n");
   printf( "Inserisci una frase : \n");
   gets(frase);
   //convertiamo tutto in minuscolo
   for (c=0; frase[c]!='\0'; ++c )
     {
       if ( frase[c] >= 'A' && frase[c]<='Z' )
         {
           frase[c] = frase[c]-'A'+'a';
         }
      }
   //elimino i blank ( gli spazi bianchi)
   for ( c=0; frase[c]!='\0'; ++c)
   {
     if ( frase[c] == ' ')
       {
         for ( d=c; frase[d]!='\0'; ++d )
           {
             frase[d]=frase[d+1];
           }
       }
    }
   //adesso guardiamo quanto è lunga la frase
   for ( c=0; frase[c]!='\0'; ++c )
   { }
   lunghezza = c;
   //vediamo se è palindroma
   for ( c=0; c<lunghezza; ++c)
     {
       if ( frase[c] != frase[lunghezza - c - 1] ) // -1 per il terminatore
         {
           ok = 0;
         }
      }
   if ( ok == 1 ) //solito flag
     {
       printf( "La frase %s e' palindroma\n" , frase);
     } else {
               printf( "La frase %s non e' palindroma\n" , frase);
            }
  system("PAUSE");
  return 0;
}
 
< Prec.   Pros. >
Firefox 2
BlueBusiness by luka@kujawa.biz