鱼C论坛

 找回密码
 立即注册
查看: 2231|回复: 2

3个数由大到小排序 函数调用

[复制链接]
发表于 2012-4-20 19:21:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
void main()
{
        void swap(int *x, int *y);
        int a, b,c;
        printf("please input a b c\n");
        scanf("%d,%d,%d",&a,&b,&c);
        swap(&a, &b);     /****这里应该怎么写???求解****/
        printf("%d,%d\n",a, b,c);
}
void swap(int *x, int *y)
{
        int temp;
        if(*x < *y)
        {
             temp = *x;
            *x = *y;
            *y = temp;
        }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-4-20 19:28:05 | 显示全部楼层
  1. #include <stdio.h>
  2. void main()
  3. {
  4.         void swap(int *x, int *y);
  5.         int a, b,c;
  6.         printf("please input a b c\n");
  7.         scanf("%d%d%d",&a,&b,&c);
  8.         if( a<b )
  9.                         swap( &a, &b );
  10.                 if( b<c )
  11.                         swap( &b, &c );
  12.                 if( a<b )
  13.                         swap( &a, &b );
  14.         printf("%d,%d,%d\n",a,b,c);
  15. }

  16. void swap(int *x, int *y)
  17. {
  18.         int temp;
  19.         if(*x < *y)
  20.         {
  21.              temp = *x;
  22.             *x = *y;
  23.             *y = temp;
  24.         }
  25. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2012-4-20 19:38:48 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 22:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表