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 Data Types and Types of data types in C

Data types specify the type of data that a variable can store. All C compilers support Five fundamental data types, they are an integer(int...

Blog Archive