Shifting Numbers Inside Array

Discussion in 'C Programming' started by go6ko01, Nov 20, 2009.

  1. go6ko01

    go6ko01

    Joined:
    Nov 20, 2009
    Messages:
    1
    Hello there,
    I am trying to do a program that shifts the nubmers in array by 1 to the right. For example we have an array with numbers [1,2,3,4] and the output should be [4,1,2,3], but apperantly I am missing stuff and I cannot find any answers ;( i looked through many websites and books but I cant find anything. Could u help me ?
    Here's my work so far:

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    
    using namespace std;
    void ShiftRight (int myArray[], int m)
    {
         int i=0;
         for (i=m-1;i<m;i--)
             {
                            myArray[i+m]=myArray[i];
             }
    }
    int main()
    {
         int i = 0;
         int myOutput;
         int myArray[i];
         int m;
         
         cout << "Please specify how many numbers will your array have: ";
         cin >> i;
         
        while ( i > 0 )
        {
              for (int m = 0; m < i; m = i - 1 ) 
              {
                  myOutput = myArray[m] << 1;
              }
        }
         
         ShiftRight(myArray[m],myOutput);
         system ("pause");
         return 0;
    }
    
    go6ko01, Nov 20, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken

    array shifting

    Ken, Dec 16, 2004, in forum: C++
    Replies:
    9
    Views:
    485
    Jonathan Mcdougall
    Dec 20, 2004
  2. woessner@gmail.com

    "Shifting" floating point numbers

    woessner@gmail.com, Mar 21, 2006, in forum: C Programming
    Replies:
    18
    Views:
    679
    Jordan Abel
    Mar 22, 2006
  3. none
    Replies:
    8
    Views:
    398
  4. GIMME
    Replies:
    5
    Views:
    186
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
  5. Surya

    Shifting string in an array

    Surya, Jan 28, 2013, in forum: C Programming
    Replies:
    8
    Views:
    235
    Shao Miller
    Jan 28, 2013
Loading...

Share This Page