Arithmetic

C语言-指针数组、指向指针变量的指针变量:输入两个整数按顺序输出

PineappleCat · 5月16日 · 2019年 859次已读

Description

键盘输入两个整数,按从大到小的顺序输出。主函数如下,请编写被调函数。

说明:

只需要编写被调函数即可,系统会自动在您提交代码的后面,加上下面的主函数

int  main()

{

       int  a[2];

       int *p[2]={&a[0], &a[1]};

       scanf(“%d%d”,&a[0], &a[1]);  //或者 scanf(“%d%d”, p[0], p[1]);

       sub(p);

       printf(“%d,%d\n”, *p[0],*p[1]); //从大到小输出两个数

       printf(“%d,%d\n”, a[0], a[1]);  //输出原来输入的两个值,不得交换

       return 0;

}

Input

输入两个整数

Output

先按大小顺序输出两个整数

再按原来的输入顺序,输出两个整数

Sample Input

12 34

Sample Output

34,12

12,34

#include <stdio.h>
#include <stdlib.h>
void sub(int **p){
    int *t;
    if(*(*p)>=*(*(p+1))){
       ;
    }else{
         t=*p;
        *p=*(p+1);
        *(p+1)=t;
    }
}
int  main()
{
       int  a[2];
       int *p[2]={&a[0], &a[1]};
       scanf("%d%d",&a[0], &a[1]);  //或者 scanf("%d%d", p[0], p[1]);
       sub(p);
       printf("%d,%d\n", *p[0],*p[1]); //从大到小输出两个数
       printf("%d,%d\n", a[0], a[1]);  //输出原来输入的两个值,不得交换
       return 0;
}

Click here to view the copyright notice of this site(点击此处查看本站版权声明)
0 条回应

必须 注册 为本站用户, 登录 后才可以发表评论!