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 8390175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:55:01+00:00 2026-06-09T18:55:01+00:00

This might seem like a stupid question but it’s really bugging me. Basically, I

  • 0

This might seem like a stupid question but it’s really bugging me.

Basically, I have a 1D array that I need to convert into a 2D array. Basically, the size of the array is: 62017 now from this, I need to get the Rows and Cols of this. But, do this dynamically, so for example, it would take the number of say: 43101 and then establish the rows+cols and then re-size the vector accordingly.

I hope I’ve explained enough and hope someone can help, thanks 🙂

  • 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-06-09T18:55:02+00:00Added an answer on June 9, 2026 at 6:55 pm

    And here it is old school array style (since I can’t access a C++0x compiler at the moment)

    #include <iostream>
    //#include <array>
    #include <inttypes.h>
    #include <math.h>
    
    void calc_new_sizes(const size_t old_size, size_t& new_size1, size_t& new_size2)
    {
        new_size1 = 1;
        new_size2 = 1;
        size_t stop_at = (size_t)sqrt(old_size) + 1;
        for (size_t i = 1; i<stop_at; i++)
        {
            if ( old_size % i == 0 )
            {
                new_size1 = i;
                new_size2 = old_size / i;
            }
        }
    }
    
    template <class T>
    T** twoDimensionify(T* p_old_array, const size_t old_size)
    {
        size_t new_size1=1, new_size2=1, old_i=0;
        calc_new_sizes(old_size, new_size1, new_size2);
        T** returnValue = new T*[new_size1];
        for (size_t i=0; i<new_size1; i++)
        {
            returnValue[i] = new T[new_size2];
            for (size_t j=0; j<new_size2; j++)
            {
                returnValue[i][j] = p_old_array[old_i];
                old_i++;
            }
        }
        return returnValue;
    }
    
    int main()
    {
        size_t old_size=20, new_size1=0, new_size2=0;
        calc_new_sizes(old_size, new_size1, new_size2);
        std::cout << "From " << old_size << " to " << new_size1 << "x" << new_size2 << std::endl;
    
        int old_array[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
        int **new_array = twoDimensionify<int>(old_array, 20);
        for (size_t i=0; i<new_size1; i++)
        {
            for (size_t j=0; j<new_size2; j++)
            {
                std::cout << "new array[" << i << "," << j << "] = " << new_array[i][j] << std::endl;
            }
        }
    
        // Clean up my memory.  This is C++ afterall.
        for (size_t i=0; i<new_size1; i++)
        {
           delete [](new_array[i]);
        }
        delete []new_array;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might seem like a stupid question but I have always wondered. What would
This might seem like a really dumb question, but I am writing an application
This might seem like a stupid question but it's been a long day. I'm
This might seem like a stupid question, but I got this ASP.NET MVC 3.0
This might seem like a stupid question I admit. But I'm in a small
Might seem like a stupid question, but I'm having an issue creating an array
This might seem like a really basic question but, When dividing the output of
this might seem like a stupid question but I've Googled to no avail. I've
This might seem like a silly question, but it's bugging me. I recently had
This might seem like a very easy question for some of you folks, but

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.