www.1862.net > C语言编程题,从键盘输入任意3个数,按从小到大的顺...

C语言编程题,从键盘输入任意3个数,按从小到大的顺...

代码1. // 输入3个数,要求按从小到大顺序输出 #include int main() { int a,b,c,t; printf("请输入三个数:"); scanf("%d%d%d",&a,&b,&c); if(a > b) { t = a; a = b; b = t; } if(a > c) { t = a; a = c; c = t; } if(b > c) { t = b; b = c; ...

//不懂继续问#include int main(){int a, b, c;scanf("%d%d%d",&a, &b, &c);if(a > b) a^=b, b^=a, a^=b; //交换ab的值 if(a > c) a^=c, c^=a, a^=c; //交换ac的值 if(b > c) b^=c, c^=b, b^=c; //交换bc的值 printf("%d < %d < %d \n", a, b, c);}

#includevoid main(){int a,b,c,t;printf("请输入三个整数:a b c\n");scanf("%d%d%d",&a,&b,&c);if(a>b){t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}if(b>c){t=b;b=c;c=t;}printf("排序后的三个整数为:%d,%d,%d\n",a,b,c);}

#include int main(void) { int a, b,k; printf("请输入2个数:"); scanf("%d %d", &a, &b); if (a < b) { k = a; a = b; b = k; } printf("%d %d\n", a, b);//这个 是最终将两个数呼互换 也可以在此基础上 进行3个数比较大小 return 0; }

(1)中for(i=0;i

#include int main(){ int s=0,a,b,c; scanf("%d%d%d",&a,&b,&c); if(a>b) { s=a; a=b; b=s; } if(a>c) { s=a; a=c; c=s; }if(b>c) { s=b; b=c; c=s; } printf("%d\t%d\t%d\n",a,b,c); getchar(); getchar(); return 0;}

int main(int argc, const char * argv[]) { int a[3] = {0}; printf("输入三个整数空格隔开:\n"); for (int i = 0; i < 3; i++) { scanf("%d", &a[i]); } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2 - i; j++) { if (a[j] > a[j + 1...

#include int _tmain(int argc, _TCHAR* argv[]){int a[3] = {0};int nTemp = 0;// 输入scanf("%d %d %d",&a[0],&a[1],&a[2]);// 冒泡排序for (int i = 0; i < 3; i++){for (int j = 0; j < i; j++){if (a[i] > a[j]){nTemp = a[i];a[i] = a[j]...

main() { int a,b,num; scanf("%d%d",&a,&b); if (a>b) {num=a;a=b;b=num;} /*因为a值大,把a值先赋给num,然后把b值赋给a,a就变小,然后把num也就是之前a的大值赋给b,这个时候就把a和b的值交换了。*/ printf("小到大排序: %d %d\n",a,b); } ...

注意本程序中scanf的输入格式,输入整数时,记得按格式,别忘记“,”,呵呵 #include void main() { int a, b, c, d, tem; printf("input four numbers:\n"); scanf("%d,%d,%d,%d",&a,&b,&c,&d); if(a>b) {tem=a;a=b;b=tem;} if(a>c) {tem=a;a=c;...

网站地图

All rights reserved Powered by www.1862.net

copyright ©right 2010-2021。
www.1862.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com