choose the max from numbers, use scanf and if else (v1:21.9.2017,v2:23.9.2017)
#include<stdio.h>
int main(){
int a,b,c,max;
printf("请输入一个数值: ");
scanf("%d",&a);
printf("请输入一个数值: ");
scanf("%d",&b);
printf("请输入一个数值: ");
scanf("%d",&c);
if(a>b){
max = a;
} else{
max = b;
}
if(max<c){
max = c;
}
printf("MAX:%d\n",max);
}
I will use another scanf to let user input the number they want to input to choose the max value.
#include<stdio.h>
int main(){
int a,b,c,max;
printf("请输入一个数值: ");
scanf("%d",&a);
printf("请输入一个数值: ");
scanf("%d",&b);
printf("请输入一个数值: ");
scanf("%d",&c);
if(a>b){
max = a;
} else{
max = b;
}
if(max<c){
max = c;
}
printf("MAX:%d\n",max);
}
I will use another scanf to let user input the number they want to input to choose the maxvalue.
#include <stdio.h>
int main() {
printf("输入需要的数字(不小于2):");
int n,a,b; //n是输入的数字
scanf("%d",&n); //a和b是为了方便设置的第一和第二个数值
int e = n - 2; //e是为了for loop设置的数字
if(n<=2){
printf("输入的数字太小!!!"); //如果设置的数字小于2的话,没有意义
}else{
printf("请输入第1个数字:");
scanf("%d",&a);
printf("请输入第2个数字:");
scanf("%d",&b);
for(int i = 1; i <= e; i++){
int x = i + 2;
printf("请输入第%d个数字:",x);
scanf("%d",&b);
if(a < b){ //如果a比b小的话,交换a和b的位置
a = b; //这里为了方便设置a为最大值
}
}
printf("最大的数字是: %d",a);
}
}
更新版本,User可以输入自己所需要数目的数值,但缺陷是,用户需要再输入之前数下数值的数目。
改进方案,除去v2中出现的scan,在loop中增加if,询问用户是否还有新的数字加入,并增加新的数值,计算用户所输入的数值的总数。
choose the max from numbers, use scanf and if else (v1:21.9.2017,v2:23.9.2017)的更多相关文章
- HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)
HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的 ...
- Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Moscow Subregional 2013. 部分题题解 (6/12)
Moscow Subregional 2013. 比赛连接 http://opentrains.snarknews.info/~ejudge/team.cgi?contest_id=006570 总叙 ...
- 835. Image Overlap —— weekly contest 84
Image Overlap Two images A and B are given, represented as binary, square matrices of the same size. ...
- [luogu3573]RAJ-Rally
先建一个$S$和$T$,$\forall 1\le i\le n$连边$(S,i)$和$(i,T)$,则最长路即为$S到T的最长路-2$ 对于这张DAG,求出一个拓扑序,点$i$为第$i$个(特别的, ...
- css基础知识点
回顾 1.结构标记 <header></header> <nav></nav> <section></section> < ...
- PAT-乙级-1015. 德才论 (25)
1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Li 宋代史学家司马光在<资治通鉴&g ...
- octave基本操作
参考: https://blog.csdn.net/iszhenyu/article/details/78712228: 吴恩达机器学习视频: 在学习机器学习的过程中,免不了要跟MATLAB.Oct ...
- [UGUI]图文混排(五):添加下划线
0.下划线标签 标签格式:<material=underline c=#ffffff h=1 n=*** p=***>blablabla...</material> mater ...
随机推荐
- AJAX的简洁写法
// ajax操作 $('#btn').on('click',function(){ var url = "{:url('confirm')}"; var actual_money ...
- luogu【P3377】 【模板】左偏树
左偏树 顾名思义 向左偏的树 (原题入口) 它有啥子用呢??? 当然是进行堆的合并啦2333普通堆的合并其实是有点慢的(用优先队列的话 只能 一个pop 一个push 来操作 复杂度就是O(n log ...
- 【BZOJ2333】棘手的操作(左偏树,STL)
[BZOJ2333]棘手的操作(左偏树,STL) 题面 BZOJ上看把... 题解 正如这题的题号 我只能\(2333\) 神TM棘手的题目... 前面的单点/联通块操作 很显然是一个左偏树+标记 ( ...
- nginx学习之rewrite
rewrite 语法学习 什么是rewrite nginx的rewrite主要功是实现URL地址重写.nginx的rewrite规则需要PCRE的支持,既可以通过Perl兼容正则表达式进行规则匹配.n ...
- Linux shell 脚本(三)
转载请标明出处: http://blog.csdn.net/zwto1/article/details/45111547: 本文出自:[zhang_way的博客专栏] 九.使用case 分支 语法 ...
- [转]SVN使用log,list,cat,diff查看所有及特定文件版本信息
[转]SVN使用log,list,cat,diff查看所有及特定文件版本信息 http://onefishum.blog.163.com/blog/static/5184730520113153402 ...
- centos6上yum安装drbd(内核:2.6.32.696)
author:headsen chen date: 2017-11-20 15:11:21 notice: 个人原创,转载请注明,否则依法追究法律责任 前期准备: 两台机器:配置主机名分别为: l ...
- MySql (MariaDB)的varchar字段的存储的是字符还是字节
关于varchar字段: 在version4之前,按字节: version5之后,按字符. 现在普遍都按字符算:无论中文英文,都算一个字符 既: varchar(10) == '123456789a' ...
- 微信扫一扫JSSDK 扫一扫报错 invalid signature 问题
交代一下业务场景 在在四个页面都需要用到扫一扫去扫二维码.然而在图三-我的订单 下单中这个页面扫一扫不起效,当时就郁闷了为啥其他页面有用,这里却没用,开始调试吧. 报错信息是签名验证不成功. 自己去打 ...
- poj 2503 查字典
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...