Wednesday, October 5, 2011

Array Element Rotating C++ Programm


#include <iostream>

using namespace std;
void  shift( int c[]);

int main()
{

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

  }
cout<<endl;  for(h=0; h<9;h++)
  {
 shift(array);

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

    std::cout << array[j] << " ";

    }
    cout<<endl;
    }

  return 0;
}
void shift(int c[])
{
 unsigned int m; unsigned int temp;
 temp = c[0];
 for(m=0; m<9; m++)
 {
 c[m] = c[m+1];
 if(m==8)
 {
 c[m]= temp;
 }
 }}