Created
December 14, 2014 12:33
-
-
Save scratchyourbrain/7f7035f4f9e7390ee701 to your computer and use it in GitHub Desktop.
C Program to swap two numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int a, b, temp; | |
printf("Enter value of a: "); | |
scanf("%d",&a); | |
printf("Enter value of b: "); | |
scanf("%d",&b); | |
temp = a; /* Value of a is stored in variable temp */ | |
a = b; /* Value of b is stored in variable a */ | |
b = temp; /* Value of temp(which contains initial value of a) is stored in variable b*/ | |
printf("\nAfter swapping, value of a = %d\n", a); | |
printf("After swapping, value of b = %d\n", b); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment