Swapping - C Programming

Posted on:
tags: , , , ,
This is Swapping program in C language by using 3 variables....
#include<stdio.h>
#include<conio.h>
void main(){
int a,b,c;
clrscr();
printf("enter the number a and b :");
scanf("%d%d",&a,&b);


c=a;
a=b;
b=c;
printf("\na=%d \nb=%d",a,b);


getch();
}

Simply take 2 variables like a=5 and b=6 and our desire result will be a=6 and b=5.
Taking a and b as input and take one more variable c by using this we will do swapping.
c=a; // by this instruction value of c will be 5 and now value of a will be the same as 5
a=b; // by this instruction value of a will be 6 and now value of b will be the same as 6
b=c; // by this instruction value of b will be 5 

if you have any query regarding the program then free to ask at youthtalentauzzar@gmail.com


No comments:

Post a Comment

< >