To Enter Two Numbers And Swap Their Values

To Enter Two Numbers And Swap Their Values




#include<stdio.h> /*tells compiler to include std input output file.*/
#include<conio.h>/*tells compilers to provide console input/output*/
     void main()
{    
        int x, y, temp;                        /*declaring 2 variables and temporary variable*/
        clrscr();                                    /*it clear the screen*/
        printf("Enter the value of x and y \n");   /*prints Enter the value of x and y in new line*/
        scanf("%d%d",&x,&y);           /*It takes input from user and addresses corresponding to x & y*/
        printf("Before swapping\nx=%d\ny=%d",x,y); /*Display unswapped value in new line*/
        temp = x;     /*stores value from x to temp*/
        x = y;           /*stores value from y to x*/
        y = temp;      /*stores value from temp to y*/
        /*using temp to swap storing x to temp and y to x then moving temp to y*/
        printf("After swapping\nx =%d\ny = %d\n",x,y);  /*It prints the value after swapping */
        getch();                                    /* return the value zero to OS*/
}



The Final Output is:


No comments