当前位置:网站首页>Use the array to calculate the average of N numbers, and output the numbers greater than the average

Use the array to calculate the average of N numbers, and output the numbers greater than the average

2022-06-26 16:41:00 Muzi..

#include<stdio.h>
#include<stdlib.h>
#define N 10
double fun(double x[],double *y)
{
    
	 int i,j;
	 double av;
	 av=0.0;
	 for(i=0;i<N;i++)
	 {
    
	 	 av=av+x[i]/N;
	 }
	 for(i=j=0;i<N;i++)
	 {
    
	 	 if(x[i]>av)
	 	 y[j++]=x[i];
	 }
	 y[j]=-1;
	 return av;
}
main()
{
    
	 int i;
	 double x[N],y[N];
	 for(i=0;i<N;i++)
	 {
    
	 	 x[i]=rand()%50;
	 	 printf("%2.0f",x[i]);
		 printf("\n");
	 }
	 printf("\nthe average is:%f\n",fun(x,y));
	 for(i=0;y[i]>=0;i++)
	 {
    
	 	 printf("%5.1f",y[i]);
	 	 printf("\n");
	 }
	 
}
原网站

版权声明
本文为[Muzi..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170506478563.html