Use C to convert the upper triangular matrix into a one dimensional array

Updated on technology 2024-04-08
8 answers
  1. Anonymous users2024-02-07

    It is implemented with heap, and the left sub-node of each node is 2*n, and the right sub-node is 2*n+1

  2. Anonymous users2024-02-06

    #include ""

    #include

    #define n 3

    main()

    int num[n][n] = ,int i;

    int j;

    int sum = 0;

    int k = 0;

    int *result;

    for (i = 1; i < n; +i)sum += i;

    result = (int *)malloc(sizeof(int)*(n*n - sum));An array of n*n with 0s is 1+2+...n-1, so the number of remaining elements is n*n-sum;

    for (i = 0; i < n; i++)for (j = 0; j < n;j++)if (i <= j) upper triangulation matrix with row subscript less than or equal to column subscript.

    result[k] = num[i][j];

    k++;for (i = 0; i < n*n - sum; i++)

    printf("%d ",result[i]);

    printf("");

    free(result);

  3. Anonymous users2024-02-05

    1. The declaration of a one-dimensional array includes the following structure: the name of the type variable [n], where n is the length of the one-dimensional array you want to define.

    Let's use an example to declare an array of type int, and assign and output the array.

    2. Enter the following statement in the main() function of the cpp file.

    inta[10];Declares a one-dimensional integer array with a length of 10.

    for (int i =0;i<10;i++)

    a[i]=i;

    cout<

    return0;

    Then Ctrl+F5 is run, and we can see the following result: the output on line i is A[i].

    3. The declarative structure of the two-dimensional array: the type variable name [m][n], where m represents the number of rows and n represents the number of columns.

    4. Enter the following ** in the main() function.

    inta[4][5];Two-dimensional array declarations.

    inti,j;

    for ( i =0;i<4;i++)

    for (j=0;j<5;j++)

    a[i][j]=(i+1)+(j+1);

    cout<

    cout<

    return0;

    Then Ctrl+F5 runs, and the resulting output is each element of the two-dimensional array, the two-dimensional array is the matrix, and each element of the array is the sum of the corresponding row and column numbers.

  4. Anonymous users2024-02-04

    1. Let's first define a second-level pointer and row and column variables [int **array,row,column; 】。

    2. Then we write the statements that enter the rows and columns.

    3. Open up an array with a one-dimensional array for it.

    4. Next, we use [array[i]=(int *)malloc(sizeof(int)*column); ] creates a new array with the array in it again.

    5. Then we can assign a value to it and output it.

    6. After running the program, we can see such an effect.

  5. Anonymous users2024-02-03

    A string is an array in itself, but it is expressed in a different form.

    On a computer, storing a string requires multiple memory addresses, and one memory address stores one character.

    You can change the address of the string pointer to output the corresponding characters.

  6. Anonymous users2024-02-02

    Receiving a string with a string type A string is an array of characters.

  7. Anonymous users2024-02-01

    C strings are stored in the char type, which is a one-dimensional array, such as char a[12] ="asdfgh";

    a[0] is put in a, if you don't understand it, post the problem**, help you solve it.

  8. Anonymous users2024-01-31

    Let's say your one-dimensional array is 100 in size

    You need to split it into a 20x5 2D matrix.

    Here's how it works:

    Suppose the subscript of a one-dimensional array is x, you can logically convert it to the subscript of a two-dimensional array: m = x 5n = x % 5 For example, if you want to find the elements in the first row and the second column, then in the one-dimensional array it is a[1].

    Converted to two-dimensional coordinates is b[0][1].

    In fact, multi-dimensional arrays, like one-dimensional arrays, are used in computers for a continuous period of memory. It's just that they don't behave in the same way.

    In addition, there is no dynamic two-dimensional array in C, and the size of the second dimension must be specified.

    A: This can be achieved with macros. For example, let's say you define a one-dimensional array a with a size of 100, and then you need someone else to enter m=8, n=9 (in many cases, it is impossible for someone else to divide the maximum value of the table in the table of the one-dimensional array exactly with m and n as you intended, that is, the one-dimensional array only needs to be large enough), and then you want to get an 8*9 two-dimensional matrix b[8][9].

    Use macro definitions (the following macro definitions are not debugged on the machine, but only provide ideas).

Related questions
3 answers2024-04-08

The base and high area of the simple input triangle are presented as follows: >>>More

10 answers2024-04-08

The first question is based on ab, the ordinate of c is high, and the area is (4+2) 4 1 2=12 >>>More

6 answers2024-04-08

#include

void main() >>>More

9 answers2024-04-08

As far as I can judge, your situation may look like this:

There are math problems that need to prove congruent triangles twice, and it may be like this. For the first time, one condition or several conditions are demonstrated. The second time a condition or several pieces are proved, and the conditions of these two proofs are added up to meet the requirements of the topic, that is, to prove the congruent triangle of two congruences. >>>More

7 answers2024-04-08

There was a slight mistake in the previous brother's solution steps, such as missing + and bc, cough cough does not affect the answer. >>>More