Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

C Program to Swap two numbers using third variable

Get two integers a and b from user and swap the values

Sample Input 1:

6 5

Sample Output 1:

5 6

Program or Solution

					    
							
#include<stdio.h>

int main()

{
    
	int a,b,t;
	printf("Enter a:");
	scanf("%d",&a);

	printf("Enter b:");
	scanf("%d",&b);

	t=a;
	a=b;
	b=t;
	printf("\nAfter Swap\na:%d b:%d",a,b);  
	return 0;

}
					    
					

Program Explanation

Get a and b using scanf statement swap the values using third variable t.

Print a and b using printf statement