0

Swapping of two numbers

Remarks:- Here I am using Dev C++ IDE  v5.11, I am writing code over this IDE. Please make sure your version before running my code over your machine .

This example contains two different techniques to swap numbers. The first program uses a temporary variable to swap numbers, and in the second program doesn’t use temporary variables.

#include<stdio.h>

main()

{

            int firstNumber,secondNumber,temp;

            printf(“Enter First Number”);

            scanf(“%d”,&firstNumber);

            printf(“Enter Second Number”);

            scanf(“%d”,&secondNumber);

            temp=firstNumber;

            firstNumber=secondNumber;

            secondNumber=temp;

            printf(“First Number is %d”,firstNumber);

    printf(“Second Number is %d”,secondNumber);

}

Output:-

Admin

Leave a Reply

Your email address will not be published. Required fields are marked *