Given two integers, swap functions to exchange two numbers of content
#include <stdio.h>
void swap (int *x,int *y);/* Function declaration */
int main ()
{
int A;
int b;
printf ("Please enter the value of a, b respectively \ n");
printf ("a=");
scanf ("%d", &a);
printf ("b=");
scanf ("%d", &b);
Swap (&A,&B);
printf ("The value of A/b after swapping is \ n");
printf ("a=%d\nb=%d\n", A, b);
return 0;
}
void swap (int *x,int *y)/* Swap function */
{
int tmp;
Tmp=*x;
*x=*y;
*y=tmp;
}
Do not create a third variable, using a function to exchange two numbers of content
#include <stdio.h>
int main ()
{
void swap (int *x,int* y);//function declaration
int A;
int b;
printf ("Please enter the value of a, b respectively \ n");
printf ("a=");
scanf ("%d", &a);
printf ("b=");
scanf ("%d", &b);
Swap (&A,&B);
printf ("The value of A/b after swapping is \ n");
printf ("a=%d\nb=%d\n", A, b);
return 0;
}
void swap (int *x,int* y)//Exchange function
{
*x=*x^*y;
*y=*x^*y;
*x=*x^*y;
}
A simple exchange of two variable values