当前位置:网站首页>Calculate the average of N numbers in the index group of X, and return the number that is less than the average and closest to the average through formal parameters
Calculate the average of N numbers in the index group of X, and return the number that is less than the average and closest to the average through formal parameters
2022-06-26 16:42:00 【Muzi..】
#include<stdio.h>
#include<stdlib.h>
#define N 10
double fun(double x[],double *av);
int main()
{
int i;
double x[N],av,m;
for(i=0;i<N;i++)
{
x[i]=rand()%50;
printf("%4.0f",x[i]);
}
printf("\n");
m=fun(x,&av);
printf("\nthe average is:%f\n",av);
printf("m=%5.1f",m);
printf("\n");
}
double fun(double x[],double *av)
{
int i,j;
double d,s;
s=0;
for(i=0;i<N;i++)
{
s=s+x[i];
}
*av=s/N;
d=32767;
for(i=0;i<N;i++)
{
if(x[i]<*av&&*av-x[i]<=d)
{
d=*av-x[i];
j=i;
}
}
return x[j];
}
边栏推荐
- R language plotly visualization: Violin graph, multi category variable violin graph, grouped violin graph, split grouped violin graph, two groups of data in each violin graph, each group accounts for
- R329 (maix-ii-a (M2A) data summary
- Dialogue with the senior management of Chang'an Mazda, new products will be released in Q4, and space and intelligence will lead the Japanese system
- Hyperf框架使用阿里云OSS上传失败
- 1-12Vmware新增SSH功能
- JUnit unit test
- 数据分析----numpy快速入门
- "C language" question set of ⑩
- Solution for filtering by special string of microservice
- [from deleting the database to running] the end of MySQL Foundation (the first step is to run.)
猜你喜欢

Stm32h7b0 replaces the h750 program, causing the MCU to hang up and unable to burn the program

知道这几个命令让你掌握Shell自带工具

TCP congestion control details | 1 summary

Make up the weakness - Open Source im project openim about initialization / login / friend interface document introduction

JUnit unit test

C语言 头哥习题答案截图

Ideal path problem

Natural language inference with attention and fine tuning Bert pytorch

Learn about common functional interfaces

Niuke Xiaobai monthly race 50
随机推荐
【从删库到跑路】JDBC 完结篇(一天学完系列!!学完赶紧跑!)
Detailed explanation of cookies and sessions
知道这几个命令让你掌握Shell自带工具
基于STM32+华为云IOT设计的云平台监控系统
Redis 迁移(操作流程建议)1
day10每日3题(1):逐步求和得到正数的最小值
r329(MAIX-II-A(M2A)资料汇总
108. simple chat room 11: realize client group chat
Kept to implement redis autofailover (redisha)
Scala Basics (II): variables and data types
Pybullet robot simulation environment construction 5 Robot pose visualization
5g is not flat and 6G is restarted. China leads wireless communication. What is the biggest advantage of 6G?
基於Kubebuilder開發Operator(入門使用)
R language plot visualization: plot visualizes the normalized histogram, adds the density curve KDE to the histogram, and uses geom at the bottom edge of the histogram_ Adding edge whisker graph with
Qt 5.9.8 安装教程
Overall context of concurrent programming
Junit单元测试
I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!
【小5聊】毕业8年,一直在追梦的路上
Tsinghua's "magic potion" is published in nature: reversing stem cell differentiation, and the achievements of the Nobel Prize go further. Netizen: life can be created without sperm and eggs