Small Data Structure exercises

Source: Internet
Author: User

/*
Set A and B to the bottom triangle matrix, and each of them is n rows and n columns. There is also a two-dimensional array C, which has n rows and n + 1 columns.
Design A scheme to store the lower Triangle Area elements in two matrices A and B in the same C.
You must store the elements in the lower Triangle Area of A in the lower Triangle Area of C, and the elements in the lower Triangle Area of B are transposed and stored in the upper triangle area of C.
The formula for calculating the storage location of matrix elements aij and B in A is given.
*/
# Include <iostream>
Using namespace std;
 
Int main ()
{
Int a [4] [4] = {1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10 }};
Int B [4] [4] = {11}, {12, 13}, {14, 15, 16}, {14, 15, 16, 17 }};
Int c [4] [5];
 
For (int I = 0; I <4; I ++)
{
Int j;
For (j = 0; j <= I; j ++)
{
C [I] [j] = a [I] [j];
}
For (j = I + 1; j <= 4; j ++)
{
C [I] [j] = B [j-1] [I];
}
}
For (int m = 0; m <4; m ++)
{
For (int n = 0; n <5; n ++)
{
Cout <c [m] [n] <"\ t ";
}
Cout <endl;
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.