Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Caricato un vettore di numeri pari ricercarne il valore massimo */
- #include <stdio.h>
- int Cerca_max(int *vett, int dim);
- int main()
- {
- int dim = 4;
- int vett[dim], num;
- // caricamento vettore
- for (int i = 0; i < dim; i++)
- {
- printf("Elemento pari (%d) : ", (i + 1));
- scanf("%d", &num);
- while ((num % 2) != 0)
- {
- puts("Devi inserire un elemento PARI!\n");
- printf("Elemento pari (%d) : ", (i + 1));
- scanf("%d", &num);
- }
- vett[i] = num;
- }
- puts("Vettore: \n");
- for (int i = 0; i < dim; i++)
- printf(" %d ", vett[i]);
- printf("\nValore massimo: %d", Cerca_max(vett, dim));
- return 0;
- }
- // ricerca del massimo
- int Cerca_max(int *vett, int dim)
- {
- int max;
- for (int i = 0; i < dim; i++)
- if (i == 0)
- max = vett[i];
- else
- if (max < vett[i])
- max = vett[i];
- return max;
- }
Add Comment
Please, Sign In to add comment