#include <bits/stdc++.h>;
using namespace std;
int main(){
long long n, nl=0; //n : So phan tu cua mang; nl : So phan tu le cua mang.
long double average=0;
cin>>n;
long long arr[n]; //Khai bao mang arr chua n phan tu.
for(long long i=0; i<n; i++){
cin>>arr[i];
if(arr[i]%2==1){
average+=arr[i];
nl+=1;
}
}
cout<<average/nl;
}
Lời giải:
program hotrotinhoc;
var a: array[1..32000] of integer;
d,i,n: integer;
s: longint;
t: real;
begin
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
d:=0; s:=0;
for i:=1 to n do
if a[i] mod 2=1 then
begin
s:=s+a[i];
inc(d);
end;
t:=s/d;
write(t:1:2);
readln
end.