Problem Statement:
Given three variables x, y, z write a function to circularly shift
their values to right. In other words if x = 5, y = 8, z = 10 after
circular shift y = 5, z = 8, x =10 after circular shift y = 5, z = 8
and x = 10. Call the function with variables a, b, c to
circularly shift values.
their values to right. In other words if x = 5, y = 8, z = 10 after
circular shift y = 5, z = 8, x =10 after circular shift y = 5, z = 8
and x = 10. Call the function with variables a, b, c to
circularly shift values.
Solution:
//Ahmad Furqan
//P5.g
#include <iostream>
#include <conio.h>
using namespace std;
void rotate(int &a, int &b, int &c)
{
int temp;
temp = c; //store c to a temporary variable
c = b; //move b to c
b = a; //move a to b
a = temp; //move temp to a,where temp contains c's original value
return;
}
void main(void)
{
int a, b, c;
a = 15;
b = 13;
c = 53;
cout << "Before Rotation:" << endl;
cout << "a=" << a << " ,b=" << b << " ,c=" << c << endl;
rotate(a, b, c);
cout << "After Rotation:" << endl;
cout << "a=" << a << " ,b=" << b << " ,c=" << c << endl;
_getch();
}
SIR YOUR PROGRAM HELP ME TOO MUCH TO ACCOMPLISH MY LAB ASSIGNMENT BUT THEIR IS A MISTAKE IN THIS PROGRAM void main(void)REPLACE WITH int main()
ReplyDelete