UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Posted on 10 Aug 2017 Category: C Views: 270

Swapping two numbers without using a third variable can be done with arithmetic operators and logic operators. Here we are using arithmetic operation method.

The idea is to get sum in one of the two given numbers. The numbers can then be swapped using the sum and subtraction from sum.

```
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b;
printf(“Enter the first number :”);
scanf(“%d”,&a);
printf(“Enter the second number :”);
scanf(“%d”,&b);
printf(“Before swap a=%d b=%d”,a,b);
a=a+b; // a now becomes the sum of a and b
b=a-b; //b stores the value of a
a=a-b; //a stores the value of b
printf(“\nAfter swap a=%d b=%d”,a,b);
getch();
}
```

##### Add two numbers C

##### C program to find factorial of a number

##### C program to generate Multiplication table using for loop

##### C program to study the Conditional Statements

##### C program to study 'Bubble Sort'

##### C program to find largest among two numbers without else.

##### C program to Sort a given set of strings

Contact : [email protected]

User IP : 54.196.46.127