c++ programs examples

C++ program to swap two numbers using function that is called by reference.

/* Write a program to swap two numbers using function that is called by
reference*/

#include<iostream.h>

 #include<conio.h>

 void swap(int *,int*);

 void main()

 {

  clrscr();

  int a,b;

  cout<<“Enter value for a=”<<endl;

  cin>>a;

  cout<<“Enter value for b=”<<endl;

  cin>>b;

  swap(&a,&b);

  cout<<“After swapping:”<<endl<<“a=”<<a<<” “<<“b=”<<b<<endl;

  getch();

  }

  void swap(int *a,int *b)

  {

   int temp;

   temp=*a;

   *a=*b;

   *b=temp;

   }

Leave a Reply

Your email address will not be published. Required fields are marked *