C programs

C Program for swapping of two Numbers by using three variables

In this program we swap value of two integers using third variable. We take values from user at runtime applies our logic to swap and then printed the swapped value on screen. To see program on swap two variable value using only two variable click here

Program

#include<stdio.h>

#include<conio.h>

void main()

{

int a=10,b=20,c=0;

clrscr();

printf("enter first no.:");   

scanf("%d",&a);               

printf("enter second no.:");  

scanf("%d",&b);                

c=a;

a=b;

b=c;

printf("first no.:%d\nsecond no.:%d",a,b); 

getch();

}

 

When Run The Program Following Output:

enter first no.:49

enter second no.:89

first no.:87

second no.:49

Description

In above program we swapped value of two variable using another third variable. Using the logic

c=a;

a=b;

b=c;

To see program on swap two variable value using only two variable click here

Releted Programs

© 2017 codewmAll rights reserved.