/*
* 1000+ C programs + tutorials
*
*
* 37_swap_two_numbers_using_temp_variable.c
*
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include
//#include
void main() {
int number_a;
int number_b;
int temp;
// clrscr();
printf("C Program to Swap values to two variables 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);
//Swampping logic
temp = number_a;
number_a = number_b;
number_b = temp;
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.