Showing posts with label swap. Show all posts
Showing posts with label swap. Show all posts

Saturday, August 9, 2014

Program to swap two numbers

Program to swap two numbers with address and pointers. Again, a necessary program for all amateur CSE students.

#include<stdio.h>
void swap(int *x,int *y)
{
 int temp;
 temp=*x;
 *x=*y;
 *y=temp;
}
void main()
{
  int a,b;
  printf("Enter the number a:");
  scanf("%d",&a);
  printf("\n Enter the number b:");
  scanf("%d",&b);
  swap(&a,&b);
  printf("\n a contain %d",a);
  printf("\n b contain %d",b);
}