PPS Practical 44

PPS Practical 44
  • Aim: Write a function Exchange to interchange the values of two variables, say x and y. illustrate the use of this function in a calling function.
  • Code:
    //For turbo C++ remove below comments
    #include <stdio.h>
    //#include<conio.h>
    void swap(int *x, int *y){
        int temp;
        temp=*x;
        *x=*y;
        *y=temp;
    }
    void main()
    {
        int a,b;
        //clrscr();
        printf("Enter a : ");
        scanf("%d",&a);
        printf("Enter b : ");
        scanf("%d",&b);
        printf("Before Swapping a=%d and b=%d\n",a,b);
        swap(&a,&b);
        printf("After Swapping a=%d and b=%d ",a,b);
        // getch();
    }
  • Output:
    Output of practical 44

Comments