# One dimensional array rotating progarm

This is a discussion on One dimensional array rotating progarm within the C++ Programming forums, part of the General Programming Boards category; Hi friends I need the one dimensional array rotating program that is the array element is 012345 123450 234501 345012 ...

1. ## One dimensional array rotating progarm

Hi friends
I need the one dimensional array rotating program
that is
the array element is
012345
123450
234501
345012
etc

2. Announcements - General Programming Boards
Announcements - C++ Programming
Announcements - General Programming Boards
Since you missed them first time around.

You need to show some effort.
You can't just say "I need" and leave it at that.

i am not an experts

4. Code:
```#include <iostream>

using namespace std;

int array[]={1,2,3,4},temp[10],i,l,j;
int main()

{

for(j=0; j<3; j++)
{

std::cout<<array[j]<<std::endl;
}
cout<<std::endl;
for(l=0;l<3; l++)
{
for(i=0; i<3; i++)
{
temp[i] = array[i];
array[i]= array[i+1];
std::cout<<array[i]<<std::endl;

}}

std::cout<<array[1]<<std::endl;
return 0;
}```

5. First, you need to indent your code better, if you hope to "see" the logic.
Code:
```#include <iostream>
using namespace std;

int array[] = { 1, 2, 3, 4 }, temp[10], i, l, j;

int main()
{
for (j = 0; j < 3; j++) {
std::cout << array[j] << std::endl;
}
cout << std::endl;

for (l = 0; l < 3; l++) {
for (i = 0; i < 3; i++) {
temp[i] = array[i];
array[i] = array[i + 1];
std::cout << array[i] << std::endl;
}
}

std::cout << array[1] << std::endl;
return 0;
}```
Second, think about some of the steps involved, and try to solve each one in turn.
Eg.
Code:
```#include <iostream>
using namespace std;

int main()
{
const int SIZE = 9;
int array[SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, j;
// before
for (j = 0; j < SIZE; j++) {
std::cout << array[j] << " ";
}
cout << std::endl;

for (j = 0; j < SIZE-1; j++) {
array[j] = array[j+1];
}

// after
for (j = 0; j < SIZE; j++) {
std::cout << array[j] << " ";
}
cout << std::endl;

return 0;
}```
Can you see how this solves part of the problem (don't just look, run the code)?

When you see it, can you then think how to get the 1 from the start to the end?

6. But sir by this code there is no rotating the output is as follows
123456789
234567899
the 9 is repeating
the last 9 is needed to change as 1 thus rotating .thanks for the code

7. Originally Posted by thannara123
But sir by this code there is no rotating the output is as follows
123456789
234567899
the 9 is repeating
the last 9 is needed to change as 1 thus rotating .thanks for the code