Monday, June 18, 2012

To swap two numbers using a third variable


/* To swap two numbers using a third variable */

#include<stdio.h>

#include<conio.h>

void main()

{

 int a,b,temp;

 clrscr();

 printf("Enter the First Number:\n");

 scanf("%d",&a);

 printf("Enter the Second Number:\n");

 scanf("%d",&b);

 printf("\nResult Before Swapping");

 printf("\nA==%d\nB==%d",a,b);

/* Swapping using third variable */

 temp=a;

 a=b;

 b=temp;

 printf("\n\nResult after Swapping");

 printf("\nA==%d\nB==%d",a,b);

 getch();

}

 

OUTPUT

Enter the First Number:

28

Enter the Second Number:

42

 

Result Before Swapping

A==28

B==42

 

Result after Swapping

A==42

B==28

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.