Header Ads

WAP to Swap 2 Number's without using temporary Variable in C - 40

This Program Swap's the 2 Number's without using temporary Variable.

Program Code:

/* Program to Swap 2 Number's without using temperary Variable. */

#include <stdio.h>
int main() 
{
 int num1, num2;

        /* get the first input from user */
        printf("Enter Number 1 : ");
        scanf("%d", &num1);

        /* get second input from user */
        printf("Enter Number 2 : ");
        scanf("%d", &num2);

        printf("Data Before Swapping Process : \n");
        printf("Num1: %d  Num2: %d\n", num1, num2);

        /* swap the given data */
        num1 = num1 + num2;
        num2 = num1 - num2;
        num1 = num1 - num2;

        /* print the results */
        printf("Data after Swapping Process : \n");
        printf("Num1: %d   Num2: %d\n\n", num1, num2);
        return 0;
  }

Program Output:

 

No comments