Swapping of Two Numbers in C

Swapping of Two Numbers in C using Temporary variables:

Swapping of Two number program in C:
#include<stdio.h>
int main()
{
 int a;
 int b;
 int c;
 printf("Type value of A = ");
 scanf("%d",&a);
 printf("\nType value of B = ");
 scanf("%d",&b);
 c=a;
 a=b;
 b=c;
 printf("A = %d  \n",a);
 printf("B = %d",b);
 return 0;
}
Output:
Type value of A = 5
Type value of B = 2
A = 2
B = 5
Explanation:
  • Three integers values of a, b, c is declared.
  • The values of a, b are taken from keyboard given by the user.
  • Now the value of “a” stored in “c” and the value of “b” stored in “a” the value of “c” stored in “b”. And last Prints the value of “a” and “b”.
See also:
Share:

Our Services

Search This Blog

  • ()
Powered by Blogger.

C Variables and Types of Variables in C

C variable is a data name that may be used to store a data value. The value of the C variable may get change in the program and it can be r...

Blog Archive