codescracker


c

C Program to Interchange two Numbers



« Previous Program Next Program »


Interchange Two Numbers in C

To interchange two numbers in C programming, make a temp variable of same type, place the first number in the temp, then place the second number in the first and place temp in the second

C Programming to Interchange two Numbers

Following C program ask to the user to enter the two number (value of A and B) to interchange and display the result on the screen:

/* C Program - Interchange Two Numbers */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int a, b, temp;
	printf("Enter value of A and B : \n");
	printf("A = ");
	scanf("%d",&a);
	printf("B = ");
	scanf("%d",&b);
	temp=a;
	a=b;
	b=temp;
	printf("Number interchanged successfully..!!\n");
	printf("A = %d\nB = %d",a,b);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program interchange two numbers

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test