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 the 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:

Ads

Search This Blog

  • ()
Powered by Blogger.

Strings in C With Syntax, C String Program with output

Strings in C :  Strings can be defined as the one-dimensional array of characters terminated by a null ('\0'). The difference betwee...

Blog Archive