计算士兵数差值,即大减小,可以用绝对值,也可以先判断大小,再做运算
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,t; 5 while(scanf("%d%d",&a,&b)!=EOF) 6 { 7 if(a>b) 8 { 9 t=a; 10 a=b; 11 b=t; 12 } 13 printf("%d\n",b-a); 14 } 15 return 0; 16 }
计算士兵数差值,即大减小,可以用绝对值,也可以先判断大小,再做运算
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,t; 5 while(scanf("%d%d",&a,&b)!=EOF) 6 { 7 if(a>b) 8 { 9 t=a; 10 a=b; 11 b=t; 12 } 13 printf("%d\n",b-a); 14 } 15 return 0; 16 }
转载于:https://www.cnblogs.com/huzhenbo113/articles/2916558.html