首页 > 代码库 > 第二次作业

第二次作业

#include<stdio.h>
int main()
{
    void swap(int *p1,int *p2);
    int a,b;
    int *pointer_1,*pointer_2;
    scanf("%d%d",&a,&b);
    pointer_1=&a;    pointer_2=&b;
    swap(pointer_1,pointer_2);
    printf("%d,%d\n",a,b);
    
 } 
 void swap(int *p1,int *p2)
 {
     int n;
      n=*p1;
     *p1=*p2;
    *p2=n;
     
 }

技术分享

总结:1、调用了一个swap函数,同是使用指针作为形参,实现两个数的交换,如果再加入一个if语句还可以实现输出较大,较小值。

              2、主函数调用错误,函数类型没有弄清楚,过程中,两个值没有调换。编程过程中小错误太多,不太仔细,导致程序无法运行。

              3、应该仔细认真,多看看课本,掌握好学习方法,多编程,熟悉c语言,对其不再陌生。多看看书上例题,认真消化,仔细钻研,争取做到最好。

第二次作业