Write a program to interchange two numbers in c or swapping of two numbers using third variable in c. or Write a c program to swap two numbers.
Write a program to interchange two numbers in c
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
printf("Before interchanging a=%d and b=%d\n",a,b);
temp=a;
a=b;
b=temp;
printf("After interchanging a=%d and b=%d",a,b);
getch();
}
Output:
Enter two numbers
2
3
Before interchanging a=2 and b=3
After interchanging a=3 and b=2
No comments: