/*
* 1000+ C programs + tutorials
*
*
* 34_swap_two_numbers_without_using_temp_variable.c
*
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include
//#include
void main() {
int number_a;
int number_b;
// clrscr();
printf("C Program to Swap values to two variables without without using temp variable : ");
printf("\n\n Enter value for variable A : ");
scanf("%i", &number_a);
printf("\n\n Enter value for variable B : ");
scanf("%i", &number_b);
printf("\n\n Before Swapping => Value A : %i B : %i ", number_a,number_b);
//Swapping logic
number_a = number_a + number_b;
number_b = number_a - number_b;
number_a = number_a - number_b;
printf("\n\n After Swapping => Value A : %i B : %i ", number_a,number_b);
// getch();
}
-
Output :
C Program to Swap values to two variables using temp variable :
Enter value for variable A : 20
Enter value for variable B : 10
Before Swapping => Value A : 20 B : 10
After Swapping => Value A : 10 B : 20
The best way to learn C programming is to practice more and more of programs .
Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.
BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.