Răspuns :
Salut! Ai mai jos rezolvarea
1. cu for
#include <iostream>
using namespace std;
int main()
{
int n, s = 0, nr_cif = 0;
cin >> n;
for (int i = 1; i <= n; ++i)
{
int x;
cin >> x;
s += x;
nr_cif++;
}
cout << s / nr_cif;
return 0;
}
2. cu while
#include <iostream>
using namespace std;
int main()
{
int n, s = 0, nr_cif = 0, i = 1;
cin >> n;
while (i <= n)
{
int x;
cin >> x;
s += x;
nr_cif++;
i++;
}
cout << s / nr_cif;
return 0;
}
3. cu do while
#include <iostream>
using namespace std;
int main()
{
int n, s = 0, nr_cif = 0, i = 1;
cin >> n;
do
{
int x;
cin >> x;
s += x;
nr_cif++;
i++;
}
while (i <= n);
cout << s / nr_cif;
return 0;
}