forked from crypticani/C_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSWAPPING.C
38 lines (38 loc) · 922 Bytes
/
SWAPPING.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
{
int n,a,b,c;
printf("Program for swapping :\nEnter your choice:\n1.Swap with a third variable.\n2.Swap without third variable.\n");
scanf("%d",&n);
switch(n){
case 1:
printf("\nEnter the value of a:");
scanf("%d",&a);
printf("\nEnter the value of b:");
scanf("%d",&b);
printf("\nThe value of a=%d\tand the value of b=%d\t before swapping.",a,b);
c=a;
a=b;
b=c;
printf("\nThe value of a=%d\tand the value of b=%d\t after swapping",a,b);
break;
case 2:
printf("\nEnter the value of a:");
scanf("%d",&a);
printf("\nEnter the value of b:");
scanf("%d",&b);
printf("\nThe value of a=%d\tand the value of b=%d\t before swapping.",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nThe value of a=%d\tand the value of b=%d\t after swapping",a,b);
break;
Default:
printf("Please enter correct option.");
}
}
getch();
}