C language में दो नंबरों को swap कैसे करें ?

Hello  friends today's our topic is how to swap of two numbers in c language .I will teach you two technique . First is swapping of two numbers with using variable and second is without using variable .

C language में दो नंबरों को swap कैसे करें ?



so lets go on code .How can we write a code for swapping of two numbers .

If you want to  know, about what is variable so ,you can follow this link :


Program for swapping of two numbers with using variable :

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c;

printf("Enter any two numbers");
scanf("%d%d",&a,&b);

c=a;
a=b;
b=c;

printf("\nValue after swapping:");
printf("\na=%d,b=%d",a,b);

getch();

}

lets do it practical:



See the image


Output:

Output

Program for swapping of two numbers without third using variable :

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b;

printf("Enter any two numbers");
scanf("%d%d",&a,&b);

a=a+b;
b=a-b;
a=a-b;

printf("\nValue after swapping:");
printf("\na=%d,b=%d",a,b);

getch();

}

lets do it practical:

without using third variable

output:

Output



Comments