pages

Thursday, 8 April 2021

c-program to swap a two number using third variables in c-programming.

 program to swap a two numbers using third variable  in c-programming.

In this program, we are making a program to swap a two numbers by getting the value of form the user.

swapping of two number means exchanging the values two variables.

suppose the we have a two variables a and b . the value of a=12 and b=15 .so, after swapping the values a=15 and b=12. In this blog we will understand how  to swap two variables in c.

#include<stdio.h>
#inlcude<conio.h>
main()
 {
     int a,b,c;
     printf("enter two number");
     scanf("%d %d",&a,&b);
     printf("before swapping; a=%d b=%d",a,b);
     c=a;
     a=b;
     b=c;
     printf("\nafter swapping; a=%d b=%d",a,b);
     getch();
 }

 output:-  a=5 and b=8

     before swapping a=5  b=8  

     after swapping a=8  b=5

No comments:

Post a Comment