赞
踩
输入三个数,分别放入变量x,y,z中
打印输入数据中最小的那一个数
定义中间变量 t
1.比较x和y的大小关系,将较小的值赋值给t
2.比较t和z的大小关系,将较小的值赋值给t
3.t 中保存的就是3个数中的较小值
(直接t=z)
代码部分:
- #include<stdio.h>
- int main( )
- {
- int x = 0;
- int y = 0;
- int z = 0;
- int t = 0;
-
- printf("Input 3 integer: ");
- scanf("%d%d%d", &x, &y, &z);
- getchar();
-
- if(x<y)
- {
- t=x;
- }
- else
- {
- t=y;
- }
-
- if(t>z)
- {
- t=z;
- }
-
- printf("The smallest is:%d\n",t);
- getchar();
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
运行结果:
代码:
- #include<stdio.h>
- int main( )
- {
- int x = 0;
- int y = 0;
- int z = 0;
-
- printf("Input 3 integer: ");
- scanf("%d%d%d",&x,&y,&z);
- getchar();
-
- if(x < y)
- {
- if(x < z)
- {
- printf("The smallest is:%d\n",x);
- getchar();
- }
- else
- {
- printf("The smallest is:%d\n",z);
- getchar();
- }
- }
- else
- {
- if(y < z)
- {
- printf("The smallest is:%d\n",y);
- getchar();
- }
- else
- {
- printf("The smallest is:%d\n",z);
- getchar();
- }
- }
-
- getchar();
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
运行结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。