当前位置:网站首页>C语言之做木桶
C语言之做木桶
2022-07-02 06:34:00 【FF小迷糊吖~】
一个木桶由10个木片围成,围成后的木桶的容量,由10个木片中最短木片的长度来表示(长度值精确到小数点后一位)。现在有100个木片,可做成10个木桶。请编写程序,对于100个有效输入(代表100个木片的长度,可以有相同的数值),输出由这些值代表的木片做成的木桶总容量的最大值(结果保留一位小数)。
如100个数值为:25.6 27.8 1.2 28.9 30.1 96.7 32.3 12.3 33.4 11.2 35.6 22.3 37.8 26.7 38.9 29.0 0.1 40.1 36.7 41.2 2.3 42.3 34.5 15.6 43.4 17.8 44.5 23.4 45.6 8.9 47.8 13.4 48.9 20.1 49.0 39.0 51.2 85.6 6.7 53.4 99.0 24.5 55.6 77.8 18.9 56.7 10.1 58.9 16.7 59.0 61.2 82.3 89.0 62.3 3.4 63.4 31.2 64.5 60.1 66.7 9.0 68.9 50.1 46.7 69.0 70.1 21.2 72.3 71.2 73.4 52.3 75.6 5.6 76.7 91.2 78.9 19.0 80.1 65.6 81.2 83.4 67.8 84.5 4.5 86.7 97.8 87.8 79.0 98.9 88.9 90.1 7.8 92.3 74.5 93.4 57.8 94.5 14.5 95.6 54.5
输出结果为451.0
编程要求:
1、请利用数组的方式实现;
2、任务提交代码时需保证其符合行业代码规范,需进行必要的缩进及换行。
#include <stdio.h>
int main(void)
{
float temp, arr[100];
float total = 0.0;
int i, j;
for (i = 0; i < 100; i++)
scanf("%f",&arr[i]);
for (i = 0; i < 99; i++) {
for (j = 0; j < 99 - i; j++) {
if (arr[j] > arr[j+1]) {
temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
}
for (i = 0; i < 100; i = i+10)
total += arr[i];
printf("Total capacity is: %.1f",total);
return 0;
}
#include <stdio.h>
int main(void)
{
float arr[100],n=0.0,b;
int a,i,j,m=0;
for(a=0;a<100;++a){
scanf("%f",&arr[a]);
}
for(i=0;i<100-1;++i){
for(j=0;j<100-1-i;++j){
if(arr[j]>arr[j+1]){
b=arr[j];
arr[j]=arr[j+1];
arr[j+1]=b;
}
}
}
while(m<100){
n+=arr[m];
m+=10;
}
printf("%.1f\n",n);
return 0;
}
边栏推荐
- ClassFile - Attributes - Code
- Hystrix implements request consolidation
- Matplotlib剑客行——没有工具用代码也能画图的造型师
- JVM指令助记符
- Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
- Redis zadd导致的一次线上问题排查和处理
- 【Go实战基础】gin 高效神器,如何将参数绑定到结构体
- Actual combat of microservices | discovery and invocation of original ecosystem implementation services
- Data type case of machine learning -- using data to distinguish men and women based on Naive Bayesian method
- 一篇详解带你再次重现《统计学习方法》——第二章、感知机模型
猜你喜欢

西瓜书--第五章.神经网络

Matplotlib swordsman line - first acquaintance with Matplotlib

概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法

【Go实战基础】gin 如何绑定与使用 url 参数

告别996,IDEA中必装插件有哪些?

Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer

Oracle modify database character set

定时线程池实现请求合并
![[staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)](/img/7f/2cd789339237b7a881bfed7b7545a9.jpg)
[staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)

In depth analysis of how the JVM executes Hello World
随机推荐
Microservice practice | teach you to develop load balancing components hand in hand
记录下对游戏主机配置的个人理解与心得
Oracle modifies tablespace names and data files
JDBC回顾
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
【Go实战基础】gin 高效神器,如何将参数绑定到结构体
Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method
分布式服务架构精讲pdf文档:原理+设计+实战,(收藏再看)
Matplotlib剑客行——初相识Matplotlib
Matplotlib剑客行——没有工具用代码也能画图的造型师
JVM指令助记符
[go practical basis] how to install and use gin
How to use pyqt5 to make a sensitive word detection tool
十年開發經驗的程序員告訴你,你還缺少哪些核心競爭力?
京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
《统计学习方法》——第五章、决策树模型与学习(上)
[staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)
[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the