C Programming

Solved Example

Practice Questions

Exercise Question

Swap two numbers


Input two numbers. Suppose numbers are stored in A and B respectively then interchange the contents of A and B.

Program / Solution:

int main() {
	int a,b,t;
	printf("Enter any two numbers: ");
	scanf("%d %d",&a,&b);
	t = a;
	a = b;
	b = t;
	printf("a = %d b = %d",a,b);
	return 0;

Sample Output:

Enter any two numbers: 5 6
a = 6 b = 5