Created
June 29, 2016 06:31
-
-
Save meditans/2d8e614b91c1871eb7cdc5184a05e71e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cmath> | |
using namespace std; | |
// Codice che definisce nel main un array, prende gli elementi di input, e | |
// chiama una funzione media esterna. Nota che media prende un puntatore ad | |
// intero (che e' il primo elemento dell'array), e la lunghezza. | |
double media(int * m, int l) | |
{ | |
int sum = 0; | |
for(int i=0; i<=l-1; i++) | |
{ | |
sum += m[i]; | |
} | |
return (sum/l); | |
} | |
int main() | |
{ | |
int n = 0; | |
cout << "Quanti numeri ha zio tobia? "; | |
cin >> n; | |
int a[n]; | |
for(int i = 0; i<=n-1; i++) | |
{ | |
cout << "Inserisci il numero " << i << ": "; | |
cin >> a[i]; | |
} | |
cout << media(a, n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment