当前位置:网站首页>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;
}
边栏推荐
- Programmers with ten years of development experience tell you, what core competitiveness do you lack?
- How to use PHP spoole to implement millisecond scheduled tasks
- Ora-12514 problem solving method
- Matplotlib剑客行——初相识Matplotlib
- Matplotlib剑客行——没有工具用代码也能画图的造型师
- 十年開發經驗的程序員告訴你,你還缺少哪些核心競爭力?
- I've taken it. MySQL table 500W rows, but someone doesn't partition it?
- Talk about the secret of high performance of message queue -- zero copy technology
- Pdf document of distributed service architecture: principle + Design + practice, (collect and see again)
- Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
猜你喜欢
数构(C语言--代码有注释)——第二章、线性表(更新版)
Chrome user script manager tempermonkey monkey
十年開發經驗的程序員告訴你,你還缺少哪些核心競爭力?
Microservice practice | Eureka registration center and cluster construction
"Redis source code series" learning and thinking about source code reading
互联网API接口幂等设计
Break the cocoon | one article explains what is the real cloud primordial
A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model
Ora-12514 problem solving method
告别996,IDEA中必装插件有哪些?
随机推荐
Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
Solution to amq4036 error in remote connection to IBM MQ
Supplier selection and prequalification of Oracle project management system
Microservice practice | declarative service invocation openfeign practice
自定义Redis连接池
[go practical basis] how to verify request parameters in gin
JDBC回顾
自定義Redis連接池
Idea view bytecode configuration
Matplotlib swordsman line - layout guide and multi map implementation (Updated)
Typora安装包分享
Customize redis connection pool
Chrome browser plug-in fatkun installation and introduction
告别996,IDEA中必装插件有哪些?
队列管理器running状态下无法查看通道
"Redis source code series" learning and thinking about source code reading
What are the differences between TP5 and laravel
CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
微服务实战|手把手教你开发负载均衡组件