it:informatica:linguaggio_c:funzioni_e_array_1
Return to Home page
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/it/informatica/linguaggio_c/funzioni_e_array_1?do=diff&rev2%5B0%5D=&rev2%5B1%5D=1551188125&difftype=sidebyside
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | it:informatica:linguaggio_c:funzioni_e_array_1 [2024/04/08 22:35] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Funzioni e Array (Esempio 1) ====== | ||
+ | **Concetti: | ||
+ | Passaggio di array a funzioni (gli array in C vengono passati alle funzioni sempre per riferimento) | ||
+ | **Testo: | ||
+ | Si realizzi una funzione che: | ||
+ | * riceve in ingresso un vettore di caratteri e la sua dimensione | ||
+ | * trasformarmi tutte le lettere maiuscole presenti nel vettore in minuscole e viceversa | ||
+ | * non esegue nessuna trasformazione sui caratteri non alfabetici | ||
+ | * restituisce il numero di trasformazioni effettuate | ||
+ | La funzione chiamante ('' | ||
+ | |||
+ | **Soluzione: | ||
+ | <file C funzioni_array_1.c> | ||
+ | /* Realizzare una funzione che riceve in ingresso un vettore di caratteri e la sua dimensione. | ||
+ | La funzione deve trasformare tutte le lettere maiuscole in minuscole e viceversa. | ||
+ | Non deve invece eseguire nessuna trasformazione sui caratteri non alfabetici. | ||
+ | La funzione deve restituire il numero di trasformazioni effettuate. | ||
+ | La funzione chiamante (main) dovra' stampare il vettore trasformato e il numero di trasformazioni effettuate. */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #define SIZE 8 | ||
+ | |||
+ | int trasforma(char v[], int dim){ | ||
+ | int i; | ||
+ | int n_modifiche=0; | ||
+ | | ||
+ | for(i=0; i<dim; i++) | ||
+ | if (isalpha(v[i])){ | ||
+ | if (islower(v[i])) | ||
+ | v[i] = toupper(v[i]); | ||
+ | else | ||
+ | v[i] = tolower(v[i]); | ||
+ | n_modifiche++; | ||
+ | } | ||
+ | |||
+ | return n_modifiche; | ||
+ | } | ||
+ | |||
+ | int main(){ | ||
+ | char vet[SIZE]={' | ||
+ | int i; | ||
+ | int n_trasf; | ||
+ | |||
+ | n_trasf = trasforma(vet, | ||
+ | | ||
+ | for(i=0; i< | ||
+ | printf(" | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | **Commenti: |
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/it/informatica/linguaggio_c/funzioni_e_array_1?do=diff&rev2%5B0%5D=&rev2%5B1%5D=1551188125&difftype=sidebyside
/web/htdocs/www.skenz.it/home/data/pages/it/informatica/linguaggio_c/funzioni_e_array_1.txt · Last modified: 2024/04/08 22:35 by 127.0.0.1