任务和代码
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,t;
scanf("%d %d",&a,&b);
if(a<b)
{
t=a;
a=b;
b=t;
}
c=a-b;
printf("%d\n",c);
return 0;
}
运行结果
知识点
if语句用法和交换的算法,这里使用的是单分支的结构。
心得
可以有几种方式完成,还能更简便点吗?
第二种方式
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if(a>b)
printf("%d\n",a-b);
else
printf("%d\n",b-a);
return 0;
}
运行结果
知识点
这里使用了双分支的结构(不知道表述的对不)
心得
殊途同归