Guest User

Untitled

a guest
Jan 13th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. // Danil Tumaykin - 4AIN - October 2011
  2. #include <stdio.h>
  3.  
  4. #define DIM 5
  5.  
  6. int max(int *vett, int numElem); // solo numeri positivi
  7.  
  8. int main()
  9. {
  10. int vett[DIM];
  11. int numElem = 0;
  12.    
  13.     while(numElem < DIM)
  14.     {
  15.         printf("Inserisci elemento numero %d: ", numElem+1);
  16.         scanf("%d", vett + numElem++);
  17.         fflush(stdin);
  18.     }
  19.  
  20.     printf("Valore massimo e': %d.", max(vett, numElem - 1));
  21.  
  22.     fflush(stdin);
  23.     getchar();
  24.     return 0;
  25. }
  26.  
  27. int max(int *vett, int numElem)
  28. {
  29.     if(numElem < 0) return 0; // volendo si puo sostituire 0 con -2147483647
  30.     if(vett[numElem] > max(vett, numElem - 1))
  31.         return vett[numElem];
  32.    
  33.     return max(vett, numElem - 1);
  34. }
Add Comment
Please, Sign In to add comment