Post my C homework came out of the experiment three arrays - 2

xiaoxiao2021-03-06  39

Experiment three arrays

First, the experimental purpose

1. Familiar with the structure 2 of the array. Master the compression storage of the matrix 3. Ability to calculate compression storage of arrays and matrices

First, experimental content

2. A and B are two N × N-order symmetric matrices. When input, the lower triangle element of the symmetric matrix is ​​input in the behavioral main sequence, and the product is stored in an algorithm to calculate the product of the symmetric matrices A and B. (Folder: symmetric matrix multiplied)

/ *

Definition of array structure type

.h * /

/ *

Const int N = 3;

Const int size = n * (n 1) / 2;

* /

#define n 3

#define size (n * (n 1) / 2)

TypedEf int Dattype;

Typedef struct {

DataType A [size], b [size], c [n] [n];

Array;

/ *

A and B are two N × N-order symmetric matrices, and when input, enter the lower triangle element of the symmetric matrix with behavioral main sequence, deposit one-dimensional array,

Write an algorithm to calculate the product of the symmetric matrices A and B.

* /

#include

#include

#include "Definition of Array Structure Type. H"

int main ()

{

Array * Pa;

/ * pa = new array; * /

PA = (array *) malloc (sizeof (array));

Printf ("Please enter the matrix A (each element of each element) = / n", size);

Input (pa-> a); / * Enter the lower triangle of the matrix A in behavioral main sequence * /

Printf ("Please enter matrix B (% D Elements) = / n", size);

INPUT (PA-> B); / * Enter the lower triangle of the matrix B in behavioral main sequence * /

MULT (PA);

PUTS ("a * b =");

Output (PA-> C); / * Output matrix C * /

System ("pause");

Return 0;

}

/ * Input of the symmetric matrix. H * /

#include "Definition of Array Structure Type. H"

Void INPUT (Datattype X [])

{

INT I;

For (i = 0; i

/ * CIN >> X [I]; * /

Scanf ("% d", x i);

Return;

}

/ * Output of the matrix. H * /

#include "Definition of Array Structure Type. H"

Void Output (DataType X [] [N])

{

INT I, J;

For (i = 0; i

{

For (j = 0; j

/ * COUT << SETW (5) << x [i] [j]; * /

Printf ("% 5d", x [i] [j]);

/ * cout << Endl; * /

PUTS ("/ n");

}

Return;

}

#include "Definition of Array Structure Type. H"

Void Mult (Array * PA)

{

Void Take (int Pb [], int P [], int J);

Int row [n];

INT col [n];

INT I, J;

INT K;

Int T;

For (i = 0; i

{

Take (PA-> A, ROW, I);

For (j = 0; j

{

Take (PA-> B, COL, J);

PA-> C [i] [j] = 0;

For (k = 0; k C [i] [j] = row [k] * col [k];

}

}

Return;

}

Void Take (int Pb [], int P [], int J)

{

INT I;

For (i = 0; i

{

IF (i> = j)

P [I] = Pb [i * (i 1) / 2 j];

Else

P [I] = Pb [j * (j 1) / 2 i];

}

Return;

}

转载请注明原文地址:https://www.9cbs.com/read-77391.html

New Post(0)