Thread: How do I shift an array in C?

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    1

    How do I shift an array in C?

    so I am trying to do a couple of things. First I want to shift the array based on the user input. So let's say the user enters (in this order): 1, 2, 3, 4, 5. I want to shift it so that it becomes 2, 3, 4, 5, 1.
    As you can see, this particular array is scalable, i.e the dimensions aren't fixed.

    Code:
    #include
    Code:
    <stdio.h>
    
    void arrayShift(int*a,int intLength);
    
    
    int main(){
    
    int arr[10]={0};//array for input numbers
    int array =0;
    
    printf("Enter the size of the array (MAX): ");
    scanf("%d",&array);
    printf("Now please enter your %d values: \n", array);
    int i;
    for(i =0; i < array; i++){
        scanf("%d", arr+i);
    }
    
    return0;
    }
    Then I want to print out the and then create a function that multiplies each number by the one before it (after shifting it): so using the same numbers as before (2, 3, 4, 5, 1), we should get an output of 2, 6, 12, 20, 5.



  2. #2
    Nasal Demon Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    179
    As you can see, this particular array is scalable, i.e the dimensions aren't fixed.
    Code:
    int arr[10]={0};//array for input numbers
    Um, sure it's fixed size. The size is 10.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to shift strings down in an array
    By plot in forum C Programming
    Replies: 7
    Last Post: 02-24-2013, 02:56 AM
  2. How to shift the bits of an array?
    By manasij7479 in forum C Programming
    Replies: 6
    Last Post: 08-13-2011, 07:42 PM
  3. Shift right for an array .
    By amir1986 in forum C Programming
    Replies: 4
    Last Post: 01-22-2011, 06:56 AM
  4. how can I shift bit right a byte array
    By lovesunset21 in forum C Programming
    Replies: 10
    Last Post: 11-03-2010, 02:31 PM
  5. array shift problem
    By splendid bob in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2002, 10:11 PM

Tags for this Thread