第七课,分支结构程序体验|三个整数输出最大值 |计算两数正差值|周薪计算

来源:互联网 发布:2017淘宝直通车 编辑:程序博客网 时间:2024/06/06 23:52
#include "stdio.h"int main(){int a,b,c,d;printf("please input three numbers\n");scanf("%d,%d,%d",&a,&b,&c);if(a<b)d=b;elsed=a;if(d<c)d=c;else d=d;printf("a,b,c中最大值为%d\n",d);return 0;}
运行结果<img src="http://img.blog.csdn.net/20150611123522142" alt="" />
</pre><pre name="code" class="cpp">知识点 单分支结构if的使用。
</pre><pre name="code" class="cpp">心得 关于scanf的使用,以前没注意过,运行都是老师给的代码。
<span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px;">如果scanf中%d是连着写的如“%d%d%d”,在输入数据时,数据之间不可以加逗号,只能是空格或tab键或者回车键——“2 3 4” 或 “2(按tab)3(按tab)4(按tab)”。若是“%d,%d,%d”,则在输入数据时需要加“,”,如“2,3,4”.</span>
<pre name="code" class="cpp">
#include "stdio.h"int main(){int a,b;//a为工时,b为总工资int c=20,d=30;//c为标准工资,d为加班工资printf("请输入工时\n");scanf("%d",&a);// 对于\n不了解。if(a>40){b=c*40+d*(a-40);}elseb=c*a;printf("总工资为%d\n",b);return 0;}


运行结果<img src="http://img.blog.csdn.net/20150611125446697" alt="" />
<img src="http://img.blog.csdn.net/20150611125509370" alt="" />
</pre><pre name="code" class="cpp">知识点 同上。
</pre><pre name="code" class="cpp">心得 对于\n了解不多,之前在scanf("%d\n",&a)这时结果要输两次。
</pre><pre name="code" class="cpp">
<pre name="code" class="cpp">#include "stdio.h"int main(){int a,b,c,d;printf("please input two numbers\n");scanf("%d,%d",&a,&b);if(a<b){c=b;b=a;a=c;d=a-b;printf("d=%d\n",d);}else{d=a-b;printf("d=%d\n",d);}return 0;}
运行结果
知识点 同上。
心得 之前else语句没加,运行出来两个结果。详细的马上还要思索。
0 0