Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>// library
- void swap(int *a, int *b){ // function and the definition. Void shows that the definition of the function is universal.
- int temp= *a;
- *a=*b;
- *b= temp; }// This is saying that *b=*a but it is inferring it by having it = temp. use transitive property.
- int main(void) {// main program.
- int M; // declare the variables as integers
- int N;
- printf("Enter values for M: ");
- scanf("%i",&M);
- printf("Enter the values for N: ");
- scanf("%i",&N);
- printf("Before swapping M: %d, N: %d\n",M, N); // This shows the results of the numers before the swap.
- swap(&M,&N); //Function call
- printf("After swapping M: %d, N: %d",M,N);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment