当前位置:网站首页>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];
}
边栏推荐
- Solution for filtering by special string of microservice
- Redis 迁移(操作流程建议)
- 架构实战营毕业设计
- LeetCode Algorithm 24. 两两交换链表中的节点
- JUnit unit test
- Codeforces Round #802 (Div. 2)
- SAP OData development tutorial - from getting started to improving (including segw, rap and CDP)
- Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock
- Pybullet robot simulation environment construction 5 Robot pose visualization
- [机缘参悟-31]:鬼谷子-抵巇[xī]篇-危机是危险与机会并存
猜你喜欢

100+ data science interview questions and answers Summary - basic knowledge and data analysis
![[graduation season] a word for graduates: the sky is high enough for birds to fly, and the sea is wide enough for fish to leap](/img/b6/21e51fa7f79d4a4b950f061703f0fb.png)
[graduation season] a word for graduates: the sky is high enough for birds to fly, and the sea is wide enough for fish to leap

Développer un opérateur basé sur kubebuilder (démarrer)

构造函数和析构函数

TCP congestion control details | 1 summary

【毕业季】致毕业生的一句话:天高任鸟飞,海阔凭鱼跃

In a bad mood, I just write code like this

我把它当副业月入3万多,新手月入过万的干货分享!
Scala 基础 (二):变量和数据类型

Oilfield exploration problems
随机推荐
MS|谢黎炜组发现混合益生菌制剂及其代谢产物可缓解结肠炎
5g is not flat and 6G is restarted. China leads wireless communication. What is the biggest advantage of 6G?
In a bad mood, I just write code like this
1-12vmware adds SSH function
MHA switching (recommended operation process)
When a programmer is disturbed 10 times a day, the consequences are amazing!
Natural language inference with attention and fine tuning Bert pytorch
Ideal path problem
【蓝桥杯集训100题】scratch辨别质数合数 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第15题
Greenplum数据库故障分析——semop(id=2000421076,num=11) failed: invalid argument
JS tutorial electron JS is a good tool for designing powerful multi platform desktop applications
"C language" question set of ⑩
IAR engineering adapts gd32 chip
proxy
proxy
长安链交易防重之布谷鸟过滤器
Data analysis - numpy quick start
[从零开始学习FPGA编程-46]:视野篇 - 集成电路的发展与技术进步
Scala 基础 (二):变量和数据类型
What is the process of switching C # read / write files from user mode to kernel mode?