Practice Program







  • How to swap two numbers?
  • void main()
    {
        int a ,b,temp;
    
    
        printf("Enter the value of a:");
        scanf("%d",&a);
        printf("\nEnter the value of b:");
        scanf("%d",&b);
    
    
        temp = a;
        a = b;
        b = temp;
    
        printf("\nAfter swapping a = %d,b = %d",a,b);
    }
    

    Output1
    Enter the value of a:12
    Enter the value of b:14
    After swapping a = 14,b = 12.
    Output2
    Enter the value of a:8
    Enter the value of b:4
    After swapping a = 4,b = 8.
    Output3
    Enter the value of a:2
    Enter the value of b:6
    After swapping a = 6,b = 2.