program to swap 2 number using 3rd variable

program to swap 2 number using 3rd variable


Hello friends looking for a program to swap two numbers  using third variable
Then where is Wiki code for this you can swap two numbers with using the source code I have provided on the blog
You may go through the source code and the algorithm and understand what is happening step by step...



c4fun brings a program to swap two numbers using 3rd vaiable.
this c program is very important as it is difficult and asked in externals,exam, vivas and in recruitment also.

we are swapping the value in variable a by value present in variable b by using a temp variable ,there also methods by which you can swap the two numbers without using 3rd variable but before that some basic ...

What is swapping what is the basic concept of swapping just might occur in your mind so shopping is simple copy the content of one variable into the other and displaying the code hey result to the user..
Below  is the source code provided for the program which you would be requiring to make a program go through this source code and understand what is happening.


The source code for the program


#include<stdio.h>
#include<conio.h>
void main()
{
int a=2,b=3,c;
clrscr();
printf("value before swapping\n");
printf(a=%d\tb=%d",a,b);
c=a;
a=b;
b=c;
printf("values after swapping\n");
printf("a=%d\tb=%d",a,b);
getch();
}



output
value before swapping
a=2 b=3
the value after swapping
a=3 b=2


Now when you have the source code and you know the program how to build it change the input try the different inputs make a different program change its look and post the comments in the comment section if you have any doubt or or quest
You can post in the comments section they would be response in no time.




Share the result with us and share the blog with your friends to help them understand and gain the knowledge of swapping program using the third variable as sharing is caring and see for fun is based on the concept of the sharing is caring help other and help your friends to know the program basic which will help them to build the confidence in them.




The above output is as  an example. You may change the output as per your requirement for desired different inputs makes available different outputs so change some inputs change some output and have fun
Let's begin a chain of commenting post your comments of the results you have got and ask your friend to see the difference and make different programs by changing some of the quotes in your program.
.



Keep learning
Keep sharing
Keep coding
Thanking you......

No comments

thanks for reading and sharing.I hope it would help you!!!!

Powered by Blogger.