版权声明:版权问题请加微信:17165380098 备注 版权问题 https://blog.csdn.net/qq_30277453/article/details/82909022
自本篇起,新题供代码与思路,旧题部分供思路。
if 选择结构 另外,也可以用abs函数来做(需要提前引入math.h库) |
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);//if选择结构
if(n>=0)
printf("%d\n",n);
else if(n<0)
printf("%d\n",-n);
return 0;
}
#include <stdio.h>
#include<math.h>//引入math库
int main()
{
int n;
scanf("%d",&n);//if选择结构
printf("%d\n",abs(n));//abs函数 fabs(x)为计算浮点型变量的绝对值的函数
return 0;
}
现将时分秒化为秒,两个时间相加减 之后用三个变量存储时分秒 输出三个变量 |
两题属于同一类。C语言中没有比较最大最小值的函数(可以自己编写最大值最小值函数) |
设置三个变量 a b c a b 分别存储 第一行的两个正数 c存储小鑫计算的结果 将a+b 与 c 进行比较 |
#include <stdio.h>
#include<math.h>
int main()
{
int a,b,c;
scanf("%d %d",&a,&b);
scanf("%d",&c);
if(a+b == c)
printf("YES\n");
else printf("NO\n");
return 0;
}
以1 0 代替女神的意思 很贴近程序猿们的日常生活 hhhh if(n==0) He he else if(n==1) I like you 祝大家都能得到else if 的结果哟! |
一种简便的方法是 设置max 等于 三个数中任意一个与另外两个进行比较 |
看题!看题! |
#include <stdio.h>
int main()
{
int m,s;
scanf("%02d:%02d",&m,&s);
if(0<m&&m<12)//对于m的多条件判断 需要各个条件分别用&&(和)连接,这一点与日常生活不同
printf("%d:%02d AM\n",m,s);
else if(m==0)
printf("%d:%02d AM\n",m+12,s);
else if(m>12)
printf("%d:%02d PM\n",m-12,s);
else if(m==12)
printf("%d:%02d PM\n",m,s);
return 0;
}
swith选择语句的应用 结构参考文献:http://www.360doc.com/content/13/1214/19/15057737_337153751.shtml |
#include <stdio.h>
int main()
{
int a,b;
char n;
scanf("%d %d\n",&a,&b);
scanf("%c",&n);
switch(n){
case'+':printf("%d\n",a+b);
break;
case'-':printf("%d\n",a-b);
break;
case'*':printf("%d\n",a*b);
break;
case'/':if(b==0) printf("Divided by zero\n");
else printf("%d\n",a/b);
break;
default:printf("input error\n");
}
return 0;
}