Header Ads

02 - WAP to Swap given Two Number's.


This program Swaps the Given two Number's.
#include 

//swap function to swap the numbers
void swap (int *x, int *y )
{
 //declaration
 int temp;
 temp = *x;
 *x = *y;
 *y = temp;

}
//main function
int main()
{
 int a, b, yes;
 while (1)
 {
  //taking input from the user
  printf ("Enter the Number of 'A' - ");
  scanf ("%d", &a);
  printf ("Enter the Number of 'B' - ");
  scanf ("%d", &b);

  //numbers before swap
  printf ("Numbers Before Swap A = %d\t B = %d\n", a, b);
  //it will call the swap function
  swap (&a, &b);

  //printing the values after swapping
  printf ("Numbers After Swap A = %d\t B = %d\n", a, b);
  //this is to run the program
  printf ("\nTo continue press ['Y'/'n'] : ");
  getchar();
  yes = getchar ();
  if (!(  yes == 'y' || yes == 'Y'))
  break;
 }
 return 0;
} 

Program Output

 

No comments