Swap and Array

this code will return output 2 3 4 5 1, i'd like to make the output is 5 1 2 3 4, can comeone help me, please?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <iostream>
#include <algorithm>
#include <conio.h>
using namespace std;

int main()
{
	int data[5];
	int i, j, tmp;
	for(i=0; i<5; i++)
	{
		cout<<"Enter 5 Number Value: "<<(i+1)<<" : ";
		cin>>data[i];
	}

	for(int i = 0; i < 4; i++)
	{
		swap(data[i],data[i+1]);
	}
	cout<<"Sorting Number: "<<endl;
	for(i=0; i<5; i++)
	{
		cout<<data[i]<<" ";
	}
	
	getch();
}
can you plae the rotate algorithm at the code, please?
feehily wrote:
can you plae the rotate algorithm at the code, please?
I do not understand your request.
can you correct the code, please? using rotate algorihtm
I know what you want your program to do, but I don't know how you want it to be done. Should the user enter five numbers and then enter the number of times to rotate it? Or do they enter the number they want to be the first number? Only you know.
the user enter five number and then the program will be return output that the last number will be at the first. example: 1 2 3 4 5, then the output is 5 1 2 3 4.
or 6 7 8 9 10, the output is 10 6 7 8 9.
You don't need arrays for this.
1
2
3
int a, b, c, d, e;
std::cin >> a >> b >> c >> d >> e;
std::cout << e << a << b << c << d << std::endl;
but it must using array and loop for. pleasee
Replace you swap in line 18 with swap(data[i],data[4]);
Topic archived. No new replies allowed.