Lorenzo1818

Esercitazione3(3)

Oct 19th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int isAverageInArray(double array[], int l){
  4.     double somma = 0.0;
  5.     for (int i = 0; i < l; i++){
  6.         somma += array[i];
  7.     }
  8.     double media = somma/l;
  9.     for (int i = 0; i < l; i++){
  10.         if (array[i] == media){
  11.             return 1;
  12.         }
  13.     }
  14.     return 0;
  15. }
  16.  
  17. void main(){
  18.     double array[] = {1.2, 5.7, 2.4};
  19.     if (isAverageInArray(array, 3)){
  20.         printf("L'array contiene un elemento il cui valore e' uguale alla media dell'intero array.");
  21.     }
  22.     else{
  23.         printf("L'array non contiene un elemento il cui valore e' uguale alla media dell'intero array.");
  24.     }
  25.     getchar();
  26. }
Advertisement
Add Comment
Please, Sign In to add comment