2.1
unknown
c_cpp
2 years ago
1.1 kB
2
Indexable
Never
#include <iostream> using namespace std; void Nhap(float[],int); void Xuat(float[],int); void Cau4(float[],int); void Cau5(float[],int); int main() { int n; cout<<"n = "; cin>>n; float *a = new float[n]; Nhap(a,n); cout<<"Cau 3 :"<<endl; Xuat(a,n); cout<<"Cau 4 :"<<endl; Cau4(a,n); cout<<"Cau 5 :"<<endl; Cau5(a,n); delete[] a; return 0; } void Nhap(float a[],int n) { for(int i =0; i < n; ++i) { cout<<"a["<<i<<"] = "; cin>>a[i]; } } void Xuat(float a[],int n) { for(int i =0; i < n; ++i) { cout<<a[i]<<"\t"; } cout<<endl; } void Cau4(float a[],int n) { for(int i =0; i < n; ++i) { if(a[i] > 0) { cout<<a[i]<<"\t"; } } cout<<endl; } void Cau5(float a[],int n) { float Sum = 0; int count = 0; for(int i =0; i < n; ++i) { if(a[i] > 0) { Sum +=a[i]; count++; } } cout<<"Trung binh cong cac so duong : "<<Sum/count<<endl; }