C LAB‎ > ‎(Sem1) Introduction to C‎ > ‎

WAP to swap two numbers using another variable.

posted Oct 29, 2010, 8:48 PM by Neil Mathew   [ updated Dec 1, 2010, 8:48 PM ]

SOURCE CODE:

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
#include<stdio.h>
 
int main()
{
 
int a,b;
 
printf("\n Enter the value of A: ");
scanf("%d",&a);
 
printf(" Enter the value of B: ");
scanf("%d",&b);
 
//Swapping:
 
int temp;
 
temp=a;
a=b;
b=temp;
 
printf("\n After Swapping... \n");
 
printf(" A: %d", a);
printf("\n B: %d", b);
 
return 0;
}

OUTPUT

 Enter the value of A: 5
 Enter the value of B: 10
 After Swapping... 
 A: 10
 B: 5
Comments