Skip to content

Instantly share code, notes, and snippets.

@scratchyourbrain
Created December 14, 2014 12:33
Show Gist options
  • Save scratchyourbrain/7f7035f4f9e7390ee701 to your computer and use it in GitHub Desktop.
Save scratchyourbrain/7f7035f4f9e7390ee701 to your computer and use it in GitHub Desktop.
C Program to swap two numbers
#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