C语言 一维数组a中有10个整数,编写程序,输出这组数的整数和及正数的平均值
给你一份C++的,C的已经有人给了
#include<iostream>
using namespace std;
int n=1000;
double *a=new double[n];
double *b=new double[n];
void sort(double a[])
{
int sum=0;int j=0;
for (int i=0;i<n;i++)
{
if (a[i]>0)
{
b[j]=a[i];
sum=sum+b[j];
j++;
}
}
cout<<"The count of positive digits is:"<<j<<"\n";
sum=sum/j;
cout<<"The average of positive digits is:";
cout<<sum<<"\n";
cout<<"The positive digits is:"<<"\n";
for (int i=0;i<j;i++)
{
cout<<b[i]<<"\n";
}
}
int main()
{
cout<<"Input the size of digits:";
cin>>n;
cout<<"\n";
cout<<"Input the digits:";
for (int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a);
return 0;
}