Write a C++ Program to Swap Numbers in Cyclic Order Using Call by Reference

C++ Program to Swap Numbers in Cyclic Order Using Call by Reference

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ Program to Swap Numbers in Cyclic Order Using Call by Reference
C++ Program to Swap Numbers in Cyclic Order Using Call by Reference

Write a C++ Program to Swap Numbers in Cyclic Order Using Call by Reference

PROGRAM:C++ Program to Swap Numbers in Cyclic Order Using Call by Reference

/* C++ Program to Swap Numbers in Cyclic Order Using Call by Reference*/

#include<iostream>
using namespace std;

void cyclicSwap(int *a, int *b, int *c);

int main()
{
int a, b, c;

cout << “Enter value of a, b and c respectively: “;
cin >> a >> b >> c;

cout << “Value before swapping: ” << endl;
cout << “a, b and c respectively are: ” << a << “, ” << b << “, ” << c << endl;

cyclicSwap(&a, &b, &c);

cout << “Value after swapping numbers in cycle: ” << endl;
cout << “a, b and c respectively are: ” << a << “, ” << b << “, ” << c << endl;

return 0;
}

void cyclicSwap(int *a, int *b, int *c)
{
int temp;
temp = *b;
*b = *a;
*a = *c;
*c = temp;
}

Leave a Reply

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