Showing posts with label Variable. Show all posts
Showing posts with label Variable. Show all posts

C Program To Swap Two Numbers Without Using Third Variable

How to write a C Program To Swap Two Numbers Without Using Third Variable in C Programming Language ?


Solution For C Program :

/*C Program To Swap Two Numbers Without Using Third Variable.*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the first no. a=");
scanf("%d",&a);
printf("Enter the second no. b=");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("After swaping numbers are:\na=%d\tb=%d",a,b);
getch();
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable


C Program To Swap Two numbers Without Third Variable

How to write a C Program To Swap Two numbers Without Third Variable in C Programming Language ?


Solution:

C Program To Swap Two numbers Without Third Variable

#include<stdio.h>

main()
{
   int a, b;

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

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

   printf("a = %d\nb = %d\n",a,b);
   return 0;
}