31 5个数求最值
来源:互联网 发布:淘宝弹弓价格及图片 编辑:程序博客网 时间:2024/05/16 06:45
5个数求最值
时间限制:1000 ms | 内存限制:65535 KB
难度:1
- 描述
- 设计一个从5个整数中取最小数和最大数的程序
- 输入
- 输入只有一组测试数据,为五个不大于1万的正整数
- 输出
- 输出两个数,第一个为这五个数中的最小值,第二个为这五个数中的最大值,两个数字以空格格开。
- 样例输入
1 2 3 4 5
- 样例输出
1 5
//连循环都不会的时候.... #include<stdio.h>int main(){int a,b,c,d,e,max,min,i;scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);if(a>b){i=a;a=b;b=i;}max=b;min=a;{if(c>b) {min=a;max=c;}else if(c<a) {min=c;max=b;}else if(b>c>a) {max=b;min=a;} if(d>b) {min=a;max=d;}else if(d<a) {min=d;max=b;}else if(b>d>a) {max=b;min=a;} if(e>b) {min=a;max=e;}else if(e<a) {min=e;max=b;}else if(b>e>a) {max=b;min=a;}printf("%d %d",min,max);}return 0;}
这样的题还是直接用循环累次求最值最好....
//循环..#include<stdio.h>int main(){int s[5]={0},i,max,min;for(i=0;i<5;i++){scanf("%d",&s[i]);}max=min=s[0];for(i=1;i<5;i++){if(s[i]>=max){max=s[i];}else if(s[i]<=min){min=s[i];}}printf("%d %d\n",min,max);return 0; }
0 0
- (31)5个数求最值
- 31 5个数求最值
- 31 5个数求最值
- 31 5个数求最值
- 31 5个数求最值
- 31 5个数求最值
- NYOJ 31 5个数求最值
- NYOJ 31 5个数求最值
- NYOJ 31 5个数求最值
- NYOJ 31 5个数求最值
- nyoj 31 5个数求最值
- NYOJ 31 5个数求最值
- NYOJ--31 5个数求最值
- NYOJ 31 5个数求最值
- 题目31 5个数求最值
- NYOJ:31-5个数求最值
- NYOJ 题目31 5个数求最值
- nyoj题目31:5个数求最值
- Http请求过程解析和模型解析
- android在eclipse中打包(签名包)方法及常见问题解决
- [CAQ1]Exception : name may not be null
- uva11297 - Census 线段树套线段树
- PHP RGB颜色和十六进制颜色互转
- 31 5个数求最值
- android 非要和EditText的光标过不去??
- C++ STL deque可变数组
- 容器
- ubuntu 12.04安装qt5.4 编译程序cannot find -lGL问题
- 错误:HttpServlet was not found on the Java
- Android动态封装圆角,按下效果的背景
- No valid signing identities (i.e. certificate and private key pair) matching
- FastDFS分布文件系统