Esercizio controllo array di stringhe
cpp
posted: Jun, 19th 2012 | jump to bottom
#include <iostream> #include <cmath> using namespace std; bool pari (string[],int ); void stampa_array(string[],int); int main() {const int N=4; string a[N]={"ale","lele","buddy","valentina"}; stampa_array(a,N); cout<<endl; if(pari(a,N)) { cout<<"Esiste una stringa di lunghezza pari nell'array dato =)"<<endl; } else cout<<"Non esiste una stringa di lunghezza pari nell'array dato =("<<endl; return 0; } bool pari(string a[],int N) { if(N==1) { if( a[0].length()%2==0) { return true; } else { return false; } } else { if( a[N-1].length()%2==0) { return true; } else { return pari(a,N-1); } } } void stampa_array(string a[],int N) { for(int i=0;i<N;i++) { cout<<*(a+i)<<endl; } }
38 views




