Jump to content
xisto Community
Sign in to follow this  
iGuest

Cpp Programming c++ programmes

Recommended Posts

1.program to convert a two dimensional array to one dimensional array.2.program to convert one dimensional array to two dimensional array.

Share this post


Link to post
Share on other sites

I think here is a good link which might help you to write such programs in C++https://answers.yahoo.com/question/index?qid=20081012031554AApY0dO:)

Share this post


Link to post
Share on other sites

So I guess if you are allowed just to copy from the internet, the link above is exactly the program you would need. But probably you would wish to be able to understand yourself how it works. So basically you have the two arrays, and then you assign an invertible function from the double array to the single array. To go one way, you apply this function when copying the array; to go the other way, you apply its inverse.

Share this post


Link to post
Share on other sites

A two dimensional array has a pair of indexes that you can work with so if you have a 3x3 array, you have 9 elements. If you want to turn the 2-dimensional array into a 1-dimensional array, you can either go with the approach in the link posted, or you can treat the 2-dimensional array as a 1-dimensional array assuming that the elements for the 2-dimensional array are stored sequentially.To do this, get a pointer to the first element of the 2-dimensional array. You can then treat the pointer as a 1-dimensional array and copy elements from it to the actual 1-dimensional array. It's one of the advantages of C wherein you can treat one piece of structured data as a totally different structure through casting and pointers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.