Introduction to C
Data Types in C
Operators in C
Hello World Program
Loops in C
Single Dimensional Array
Two Dimesnional Arrays
Array Example Programs
To start with the program, first its good to understand about swapping. Its possible that many people may not aware of this term. If you know, its good. Swap means interchange. Swap two numbers means to interchange the values of two numbers from each other. Suppose, x=15 and y=20. Then after swapping it will be x=20 and y=15. We have to write the program for the same. So, here we go:
Before swapping, x=15 and y=20 (15 and 20 are the examples.. lets say these values are entered by user)
After Swapping, x=20 and y=15
Here, x and y are the two variables between which swapping has to be done. But, if we do first x=y. It means that value of y will be stored to x. But, now we have to get value of x stored in y. But, now its not possible because original value of x is lost as it holds now value of y. So, here we have used a third variable called temp(or say temporary). In this variable, firstly we have stored the value of x so that original value of x is not lost and then this value is assigned to y. In this way, these numbers are swapped.
Now, lets say you do it(swapping) without using third variable('temp' here). Wondering how is it possible. No need to wonder more... Here, I show you, how to do it???
x = x+y; => x = 15+20 => x = 35 y = x-y; => y = 35-20 => y=15 x = x-y; => x = 35-15 => x=20
Note: If find any issues/errors with the tutorial above, please immediately mail it to firstname.lastname@example.org