Ad

Chapter - 3: Graduating to C++

Complete the following program by defining the function swapb() and its prototype such that the output of the program is 20 10


Ad
D
Sections
5
Exercises
#include<iostream>
using namespcae std;
 void swapa (int &, int &);
 
 int main()
 {
 	int a = 10, b = 20;
 	
 	swapa(a,b);
 	cout << a << " " << b;
 	return 0;
 }
 
 void swapa(int &x, int &y)
 {
 	swapb(x,y);
 }

Answer:

#include<iostream>

using namespace std;

void swapa(int &, int &);
void swapb(int &, int &);

int main()
{
	int a = 10, b = 20;
	
	swapa(a,b);
	cout << a <<" "<< b;
	
	return 0;
}

 void swapa(int &x, int &y)
 {
 	swapb(x,y);
 }
 
 void swapb(int &a, int &b)
 {
 	int temp;
 	temp = a;
 	a = b;
 	b = temp;
 }
Ad

© 2024 Garbage Valuegarbage value logo