Skip to main content
Write a program to swap two numbers using a temporary variable
#include<stdio.h>#include<conio.h>
void main()
{
int num1, num2, temp;
clrscr();
printf("\n Enter the first number: ");
scanf("%d" ,&num1);
printf("\n Enter the second number: ");
scanf("%d",&num2);
temp=num1;
num1=num2;
num2=temp;
printf("\n the first number is %d", num1);
printf("\n the second number is %d", num2);
getch();
}
Output
Enter the first number:3Enter the second number:5
the first number is 5
the second number is 3
Comments
Post a Comment