C program for swapping numbers
#include <stdio.h>
void swap(int *num1, int *num2)/*Defining function for swapping the numbers*/
{
int temp; /*using third variable to store data of numbers*/
temp = *num1;
*num1 = *num2;
*num2 = temp;
}
int main ()//driver function
{
int a,b;
printf("Enter the numbers for swapping\\");//taking input
scanf("%d %d",&a,&b);
printf("The numbers before swapping is a =%d and b=%d \\",a,b);
swap(&a, &b);//calling function for swaping
printf("The numbers after swapping is a=%d and b=%d",a,b);
return 0;
}
Output
Enter the numbers for swapping 3,4
The numbers before swapping is a =3 and b=4
The numbers after swapping is a=4 and b=3