Like Tree1Likes
  • 1 Post By Salem

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. #1
    Registered User
    Join Date
    Mar 2011
    Location
    India ,Kerala
    Posts
    23

    Thumbs down 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. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    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.
    AndrewHunter likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Location
    India ,Kerala
    Posts
    23
    please give the logic
    i am not an experts

  4. #4
    Registered User
    Join Date
    Mar 2011
    Location
    India ,Kerala
    Posts
    23
    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. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Location
    India ,Kerala
    Posts
    23
    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. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,888
    Quote 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
    The code example was meant to help you along, not provide you with a completely working solution. So, what can you do about this observation?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Mar 2011
    Location
    India ,Kerala
    Posts
    23
    Okay thanks for helping i am trying to get my need i will post soon

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rotating array
    By Darkinyuasha1 in forum C++ Programming
    Replies: 7
    Last Post: 08-15-2009, 09:20 AM
  2. BIOS progarm in C needed
    By naveenaks03 in forum C Programming
    Replies: 3
    Last Post: 05-03-2008, 05:20 AM
  3. Rotating function for array
    By Fredir in forum C++ Programming
    Replies: 2
    Last Post: 11-29-2007, 12:37 PM
  4. Replies: 1
    Last Post: 04-25-2006, 12:14 AM
  5. progarm doesnt compile
    By kashifk in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2003, 05:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21