C program swap two numbers Implementation of this program is very simple.
Swapping of two numbers: For swapping number first we have 2 numbers and using the third variable we swap the numbers.
C program swap two numbers
int first,second,temp; //declaring variable
scanf("%d",&first); // take input first number
printf("Enter second \n");
scanf("%d",&second);//take second number input
printf("before swaping\n first = %d \n second = %d \n",first ,second );
temp = first ;
first = second;
second = temp;
printf("after swaping\n first = %d \n second =%d",first,second);
- Initialized variables first ->1st number, second ->second number , temp ->temporary variable
- Take input values
- Now Swap values using third variable temp = first, first = second, second = temp
- Print swapped values