Swapping by using 2 variables - C Programming

Posted on:
tags: , , , ,


This program is about swapping any two numbers by using 2 variables....
#include<stdio.h>
#include<conio.h>
void main(){
int a,b;
clrscr();
printf("enter the number a and b :");
scanf("%d%d",&a,&b);

a=a+b;//step 1
printf("after step 1: a=%d\n\n",a);
b=a-b;//step 2
printf("after step 2: b=%d\n\n",b);
a=a-b;//step 3
printf("after step 3: a=%d\n\n",a);

printf("final swapping: \na=%d \nb=%d",a,b);

getch();
}


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



No comments:

Post a Comment

< >