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 ...
随机推荐
- jquery初始化的三种方式
第一种 $(document).ready(function(){ alert("第一种方法."); }); 第二种 $(function(){ alert("第二种方法 ...
- Windows DLL资料整理
1.使用Visual C++ 6.0创建dll 2. 函数的调用规则(__cdecl,__stdcall,__fastcall,__pascal) 要点: 1. 如果你的程序中没有涉及可变参数,最好使 ...
- vs不支持通过afxgetmainwnd()获取窗口句柄(转)
问题: 在vc6中这样代码顺利通过,可执行 ::SetDlgItemText(AfxGetMainWnd()-> m_hWnd,IDC_TIME,strTime); (这是在对话框程序中,代码在 ...
- C#异常处理--C#基础
try...catch:捕获异常try...finally:清除异常try..catch...finily:处理所有异常 1.捕获异常 using System; using System.Colle ...
- json 的循环输出
json不能用for-of循环,会报错 可以用for-in循环: var json = {'a':'apple','b':'banana','c':'orange','d':'pear'}; for( ...
- springmvc后台取值中文乱码问题
字符-->字节.字节-->字符时需要用到编码(Encoder).解码(Decoder) 几种编码: ASCII:总共128 ISO-8859-1:涵盖大部分西欧语言字符.一个字符一个字节表 ...
- React-Native安装使用
先附上React-Native官方文档中文版:http://wiki.jikexueyuan.com/project/react-native/getting-started.html 好,接下来我们 ...
- java导出word
public void dayinHw(HttpServletRequest request, HttpServletResponse response){ String id = request.g ...
- static与final的区别
final被修饰的变量为常量一旦赋值不能修改,被修改的方法为最终方法不能被重写,被修饰的类是最终类,不能被继承static被修饰的变量和方法,为该整个类及其类的对象所共享,一个类或对象修改了被定义的类 ...
- UWP 使用Telerik Grid控件
还是老规矩,看一下最终效果. 数据是从SQLite中读取,然后绑定到DataGrid中显示的. 先看一下XAML <grid:RadDataGrid Grid.Row="1" ...