/*****************************************************************/ // File : swap.c // Purpose : Swaps the contents of 2 variables without any additional variable // Author : Nanda Kishor K N // Mail Id : knnkishor@yahoo.com, nandakishorkn@rediffmail.com // Website : www.c4swimmers.esmartguy.com ( WEB MASTER ) // Group : c4swimmers@yahoogroups.com ( GROUP OWNER ) /*****************************************************************/ #include /* Name : main() Purpose : This is the main function that accepts TWO values and swaps the contents without any additional variable. This does not call any other function. Parameter : None */ int main() { // Variable Declarations & Initialization // Naming conventions are used like all integer variables should begin with 'i' int iA,iB; // Accept TWO values from the user printf("Enter 2 values : "); scanf("%d %d",&iA,&iB); printf("\nBefore Swapping :\nFirst Value=%d Second Value=%d",iA,iB); // Swap the contents iA = iA + iB; iB = iA - iB; iA = iA - iB; // Display the result or contents of the variables after swapping printf("\nAfter Swapping :\nFirst Value=%d Second Value=%d",iA,iB); return 0; } // End of main() program