pages

Saturday, 10 April 2021

c-program to swap the two number without using the third variables.

 program to swap the two number without using third variables in c-programming?

program to swap two numbers without third variable in c program.

we will swap/exchange of  two numbers without using third variable are given below:


#include<stdio.h>
#include<conio.h>
main()
{
    int a,b;
    printf("enter two number");
    scanf("%d %d",&a,&b);
    printf("before swapping a=%d and b=%d",a,b);
    a=a+b;
    b=a-b;
    a=a-b;
    printf("after swapping a=%d and b=%d",a,b);
    getch();
}

output:-  before swapping a=3  and b=5
             after swapping a=5 and b=3

No comments:

Post a Comment