当前位置:网站首页>Calculate the average of N numbers in the group indexed by the formal parameter x, move the data less than the average in the group indexed to the front of the array, and move the data greater than or
Calculate the average of N numbers in the group indexed by the formal parameter x, move the data less than the average in the group indexed to the front of the array, and move the data greater than or
2022-06-26 16:44:00 【Muzi..】
#include<stdlib.h>
#include<stdio.h>
#define N 10
double fun(double *x);
int main()
{
int i;
double x[N];
for(i=0;i<N;i++)
{
x[i]=rand()%50;
printf("%4.0f",x[i]);
}
printf("\n");
printf("the average is:%f\n",fun(x));
printf("\n the result:\n",fun(x));
for(i=0;i<N;i++)
{
printf("%5.0f",x[i]);
}
printf("\n");
}
double fun(double *x)
{
int i,j;
double y[N];
double av=0;
for(i=0;i<N;i++)
{
av+=x[i]/N;
}
for(i=j=0;i<N;i++)
{
if(x[i]<av)
{
y[j]=x[i];
x[i]=-1;
j++;
}
}
i=0;
while(i<N)
{
if(x[i]!=-1)
y[j++]=x[i];
i++;
}
for(i=0;i<N;i++)
{
x[i]=y[i];
}
return av;
}
边栏推荐
- C language --- basic function realization of push box 01
- This year, the AI score of college entrance examination English is 134. The research of Fudan Wuda alumni is interesting
- QT 5.9.8 installation tutorial
- What is flush software? Is it safe to open an account online?
- Scala 基礎 (二):變量和數據類型
- 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
- 当一个程序员一天被打扰 10 次,后果很惊人!
- Scala Foundation (2): variables et types de données
- 108. 简易聊天室11:实现客户端群聊
- 【207】Apache崩溃的几个很可能的原因,apache崩溃几个
猜你喜欢

Screenshot of the answers to C language exercises

Science | 红树林中发现的巨型细菌挑战传统无核膜观念

Junit单元测试

Vibrating liquid quantity detecting device

基於Kubebuilder開發Operator(入門使用)

How to implement interface current limiting?

对话长安马自达高层,全新产品将在Q4发布,空间与智能领跑日系

# 补齐短板-开源IM项目OpenIM关于初始化/登录/好友接口文档介绍

我把它当副业月入3万多,新手月入过万的干货分享!

进军AR领域,这一次罗永浩能成吗?
随机推荐
Stm32f103c8t6 realize breathing lamp code
TCP congestion control details | 1 summary
108. 简易聊天室11:实现客户端群聊
proxy
Knowing these commands allows you to master shell's own tools
【MATLAB项目实战】基于卷积神经网络与双向长短时(CNN-LSTM)融合的锂离子电池剩余使用寿命预测
When a programmer is disturbed 10 times a day, the consequences are amazing!
Data analysis - numpy quick start
Screenshot of the answers to C language exercises
JS教程之使用 ElectronJS、VueJS、SQLite 和 Sequelize ORM 从 A 到 Z 创建多对多 CRUD 应用程序
Develop operator based on kubebuilder (for getting started)
Constructors and Destructors
精致妆容成露营“软实力”,唯品会户外美妆护肤产品销量激增
What is the preferential account opening policy of securities companies now? Is it safe to open an account online now?
C语言 头哥习题答案截图
Least squares system identification class II: recursive least squares
mha 切换(操作流程建议)
C语言所有知识点小结
JS教程之使用 ElectronJS 桌面应用程序打印贴纸/标签
LeetCode Algorithm 24. Exchange the nodes in the linked list in pairs