• [山东科技大学OJ]1107 Problem A: 编写函数:Swap (I) (Append Code)


     

    Time Limit: 1 Sec Memory Limit: 16 MB

    Submit: 17642 Solved: 11482

    [Submit][Status]

    Description

    编写用来交换两个数的函数,使得“Append Code”中的main()函数能正确运行。

     

    -----------------------------------------------------------------------------

     

    用C实现三个函数int_swap()、dbl_swap()、SWAP(),其中SWAP()是个带参宏。

     

    用C++实现两个函数,都以Swap()命名。

     

    以上函数的调用格式见“Append Code”。这里不给出函数原型,它们的参数请通过main()函数自行确定。

     

    Input

    输入为4行,每行2个数。

     

    Output

    输出为4行,每行2个数。每行输出的两数为每行输入的逆序。

     

    Sample Input

    12 57

    9 -3

    -12 4

    3 5

    Sample Output

    57 12

    -3 9

    4 -12

    5 3

    HINT

    “Append Code”中用到的头文件、全局变量或宏的定义应自行补充。

     

    Append Code

    append.c, append.cc,

    [Submit][Status]


    #include

    #include

    #include

    #include

    #define SWAP(t,x,y){t=x;x=y;y=t;}

    int_swap(int *a,int *b)

    {

        int t;

        t=*a;

        *a=*b;

        *b=t;

    }

     

    dbl_swap(double *a,double *b)

    {

        double t;

        t=*a;

        *a=*b;

        *b=t;

    }

     

     

    int main()

    {

        int x1, y1, t1;

        double x2, y2, t2;

     

        scanf("%d %d", &x1, &y1);

        int_swap(&x1, &y1);

        printf("%d %d\n", x1, y1);

     

        scanf("%d %d", &x1, &y1);

        SWAP(t1, x1, y1);

        printf("%d %d\n", x1, y1);

     

        scanf("%lf %lf", &x2, &y2);

        dbl_swap(&x2, &y2);

        printf("%lg %lg\n", x2, y2);

     

        scanf("%lf %lf", &x2, &y2);

        SWAP(t2, x2, y2);

        printf("%lg %lg\n", x2, y2);

    }

  • 相关阅读:
    Clusterpedia 入围 “全球开源软件产品评选活动” 优胜奖
    基于Springboot的网课管理系统
    【数据结构】 顺序表
    基于单片机的空调的温度控制系统设计
    中国电影城市排名易语言查询代码
    TOGAF之架构标准规范(一)
    设计师都应该知道的事:极简主义家具该怎么去用
    Node.js躬行记(24)——低代码
    C++经典面试题:内存泄露是什么?如何排查?
    vb加了me
  • 原文地址:https://blog.csdn.net/m0_73840805/article/details/127818862