Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:24:31+00:00 2026-05-26T21:24:31+00:00

after reading inputs to an array: int * inputs; the inputs is 1 dimensional

  • 0

after reading inputs to an array:

int * inputs;

the “inputs” is 1 dimensional array: inputs[6], then reading this array out, the values are:

inputs[0]=1
inputs[1]=2
inputs[2]=3
inputs[3]=4
inputs[4]=5
inputs[5]=6

I would like to read this array into another one dimensional array:

int counter=0;
int * allElements = new int[6];

for(int i=0; i<6; i++)
{
      allElements[counter++] = inputs[i];
}

That is a traditional way of reading all of the elements into one dimensional array and I believe if I read the elements of “allElements” this way:

for(int i=0; i<6; i++)
   printf("%d ", allElements[i]);

and it should be: 1 2 3 4 5 6

However, I would like to read all elements of that array into the 1 dimensional array such that when I do it like this:

for(int i=0; i<6; i++)
   printf("%d ", allElements[i]);

It should be: 1 3 5 2 4 6

How can I achieve this way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:24:32+00:00Added an answer on May 26, 2026 at 9:24 pm

    What about:

    for(int i=0; i<6; i++)
    {
        allElements[i] = inputs[2*(i%3) + (i/3)];
    }
    

    Imagine inputs is a two-dimension array, of 3×2, then i%3 is one coordinate and i/3 the other. Just transpose it into a 2×3 matrix, and done!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

after reading inputs to an array: std::vector<unsigned char *> inputs(elements); the inputs is a
I can't seem to figure out why this falls into a loop after getting
After reading this question , I was reminded of when I was taught Java
After reading this description of late static binding (LSB) I see pretty clearly what
After reading this answer: best way to pick a random subset from a collection?
I'm C++ begginer. I did this excercise from Deitel's book: Use a one-dimensional array
After reading some information I thought this should work. The JS function is called
After reading the android documentation about String, which includes this: This class is implemented
After reading the Head First Design Patterns book and using a number of other
After reading a bit more about how Gnutella and other P2P networks function, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.