Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Sviluppare una function C che, dati come parametri di input un array di char e il suo
- size, determina e restituisce come parametro di un dato logico che indica se il testo
- nell’array è un pangramma, ovvero è un testo che contiene, almeno una volta, tutte
- le 21 lettere dell’alfabeto italiano.
- **/
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int pangramma(int n, char s[]) {
- char alfabeto[] = "abcdefghilmnopqrstuvz";
- int i,j;
- int occor[21];
- for(i = 0; i < 21; i++)
- occor[i] = 0;
- for(i=0;i<n;i++)
- {
- s[i]=tolower(s[i]);
- }
- for(i=0;i<n;i++) {
- for (j=0;j<21;j++) {
- if(s[i] == alfabeto[j]) {
- occor[j]++;
- }
- }
- }
- // Scorro tutto l'array delle occorrenze, se trovo un solo 0, significa che una lettera
- // non è presente nella stringa, ritorno 0 perchè non è un pangramma e esco
- // Se invece non trovo nessuno 0, ritorno 1, la frase è un pangramma.
- for(j=0;j<21;j++)
- {
- if(occor[j]==0) {
- return 0;
- break;
- }
- }
- return 1;
- }
- int main() {
- char s[]="Pochi sforzan quel gambo di vite";
- int n;
- n=strlen(s);
- int a;
- a=pangramma(n,s);
- printf("%d",a);
- }
Advertisement
Add Comment
Please, Sign In to add comment