Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


Swap Two Numbers Using C Program


Swapping means exchanging the values of two Variables.The following example shows, how to Swap two numbers using C Program.

Example : pgm.c

#include<stdio.h>
int main(){
    int a,b,c;
    printf("\nEnter the value of A and B : ");
    scanf("%d%d",&a,&b);
    printf("\nBefore Swapping : ");
    printf("\nA value is %d",a);
    printf("\nB value is %d",b);
    c=a;
    a=b;
    b=c;
    printf("\nAfter Swapping : ");
    printf("\nA value is %d",a);
    printf("\nB value is %d",b);
    return 0;
}

Output:

Enter the value of A and B :
 10
 20

Before Swapping :
 A value is 10
 B value is 20

After Swapping :
 A value is 20
 B value is 10