Răspuns :
#include <iostream>
using namespace std;
int main() {
unsigned n;
cin>>n;
int x, s = 0, nr=0,spoz=0,i;
for(i=0;i<n;i++){
cin>>x;
if(x>=0){
spoz+=x;
nr++;
}
else{
s+=x;
}
}
cout<<"Suma numerelor negative: "<<s<<endl;
cout<<"Media aritmetica a numerelor pozitive: "<<(float)spoz/nr;
return 0;
}
using namespace std;
int main() {
unsigned n;
cin>>n;
int x, s = 0, nr=0,spoz=0,i;
for(i=0;i<n;i++){
cin>>x;
if(x>=0){
spoz+=x;
nr++;
}
else{
s+=x;
}
}
cout<<"Suma numerelor negative: "<<s<<endl;
cout<<"Media aritmetica a numerelor pozitive: "<<(float)spoz/nr;
return 0;
}
Intreg n, i, x, ma, s, nr;
Citeste n;
Ma<-0; s<-0; nr<-0;
Pentru i<-1,n executa
Citeste x;
Daca x>0 atunci ma<-ma+x; nr<-nr+1;
Altfel s<-s+x;
->
->
Ma<-ma/nr;
Scrie "media aritmetica a numerelor pozitive este ", ma,". ",
"Suma numerelor negative este ", s;