0 votes
170 views
in Practical Questions by (245 points)
edited
Write a function in C++ that exchanges data using swap function to interchange the given two numbers .

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer

This is a practical question so will try to understand the concept , the question said us to use swap function

This code is error free might only work with turbo C++ 


#include <iostream.h>
#include<conio.h>
void swap(float &x,float &y)
{
 float t=x;
 x=y;
 y=t;
 
}

int main()
{void swap(float &x,float &y);
float a,b;
cin>>a>>b;
cout<<"a="<<a<<"b="<<b<<endl;
swap(a,b);
cout<<"a="<<a<<"b="<<b<<endl;
 
}

We added a output for you to get it clearly 

image

Related questions

0 votes
1 answer 158 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

535 users

...