Filled Under:

C program to swap two numbers without using a third variable

C program to swap two numbers without using a third variable


C program to swap two numbers without using a third variable


 In this program, I have discussed about the C program to swap two numbers without using a third variable.

Swap means to interchange the values of two variables.

Here I have not used a third variable to swap the two numbers.

----------------------------------------------------------------------------------------------------------------

#include<stdio.h>
void main()
{ int a,b;
printf("Enter two numbers: ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("the two numbers are: \n");
printf("%d \n",a);
printf("%d \n",b);
}

-----------------------------------------------------------------------------------------------------

If you want the C program to swap two numbers using a third variable then click here.

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.


0 comments:

Post a Comment

 

Copyright 2020 Programming in C All Right Reserved