Skip to content

Instantly share code, notes, and snippets.

@wohhie
Created July 19, 2016 12:32
Show Gist options
  • Save wohhie/929581f8d3a51f92cfe4dbc427b89bc4 to your computer and use it in GitHub Desktop.
Save wohhie/929581f8d3a51f92cfe4dbc427b89bc4 to your computer and use it in GitHub Desktop.
C program to read two integers M and N and to swap their values.
#include <stdio.h>
//swap function for swaping the value.
void swap(int *ptr1, int *ptr2);
int main() {
int num1, num2;
printf("Enter two number: ");
scanf("%d %d", &num1, &num2);
printf("before swaping M: %d\t N: %d,", num1, num2);
printf("\n");
swap(&num1, &num2);
printf("after swaping M: %d\t N: %d,", num1, num2);
printf("\n");
return 0;
}
//swap function for swaping the value.
void swap(int *ptr1, int *ptr2) {
int temp;
temp = *ptr1;
*ptr1 = *ptr2;
*ptr2 = temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment