C language exam matrix conversion, how to use C language to convert adjacency matrix to reachable ma

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

    #include

    int main()

    int x,y,i,j;

    printf("Please enter the rows and columns of the sparse matrix");

    scanf("%d %d",&x,&y);

    int arr[x][y];

    printf("Please enter a sparse matrix");

    for(i=0;ifor(j=0;jscanf("%d",arr[i][j]);

    for(i=0;ifor(j=0;jif(arr[i][j])

    printf("%d %d %d",i,j,a[i][j]);

    Note: This program uses variable length arrays, which are not suitable for all compilers, so run the modified program to check whether your compiler supports variable arrays.

  2. Anonymous users2024-02-06

    I wanted to do it, but the 4th floor is perfect, and you should give it to him.

    If you think what I'm saying is right,。。 Well... You can give me extra points... Well...

  3. Anonymous users2024-02-05

    50 points....For such a simple question, you would use fifty points....

    Okay....P.S. I remember that I said this question a few days after I first learned pascal....It's nothing more than scanning, recording...

  4. Anonymous users2024-02-04

    Can you write it clearly?

  5. Anonymous users2024-02-03

    If the array is a square, it can look like this:

    for(int i=0;i

    If it's an m*n matrix, you'll need to reorganize the array, but the principle is pretty much the same.

  6. Anonymous users2024-02-02

    The first step, double circulation: adjacency matrix + identity matrix.

    for i=0 to shangxian (i++)for j=0 to shangxian (j++)if i=j then a[i,j]=a[i,j]+1 (the value on the diagonal of the identity matrix is 1).

    nextj,i

    In the second step, the resulting matrix is multiplied by itself (double cycle). Matrix multiplication requires a lot of words, so I won't write about it, but I believe you know, at least you should be able to look it up.

    In the third step, the matrix obtained after multiplication is compared with the matrix before multiplication, (which is also a double cycle). If it is equal, it will be done, otherwise it will be repeated.

    Step 2 and 3. If automated.

    The multiplication and comparison process of two and three requires a layer of conditional looping on the outside.

  7. Anonymous users2024-02-01

    Write a general one for you.

    If you want other matrices multiplied by a few times, you can modify the values of n and m to include

    #define n 3

    #define m 4

    int array[n][m];

    int turn[m][n];

    void main()

    printf("");

    printf("The matrix before transpose is:");

    for(i=0;i calls the matrix transpose function.

    convert(array,turn);

    printf("");

    printf("The transposed matrix is:");

    for(i=0;ivoid convert(int array[n][m],int turn[m][n])

  8. Anonymous users2024-01-31

    The above one is well written, don't do it.

  9. Anonymous users2024-01-30

    #include

    #include

    int main()

    for(i=0;i<=3;i++) output your input matrix;

    printf("");}

    printf("");

    for(i=0;i<=3;i++) conversion matrix;

    printf("");

    system("pause");}

  10. Anonymous users2024-01-29

    #include

    #define n 1024

    void main()

    int i, j,k,n,m,a[n][n];

    printf(("Please enter m:"

    scanf("%d",&m);

    printf(("Please enter n:"

    scanf("%d",&n);

    printf("Please enter %d*%d element:"m,n);

    for(j=0;jfor(k=0;kscanf("%d",&a[j][k]);

    for(i=0;ifor(j=0;jprintf("%d",a[i][j]);

    printf("");

  11. Anonymous users2024-01-28

    Here is an analysis for you... Why has the front been changed, but the back output has not been changed? The reason is simple. You have made two exchanges ...

    For example, when i=1 and j=3, you swap t[1][3] and t[3][1], and when the program runs to i=3 and j=1, do you swap t[3][1] and t[1][3] again?

    Think about it ... Hehe... Two exchanges were made and all the work was done in vain...

    The solution is to define a two-dimensional array to store the swapped values...

    #include

    using namespace std;

    main(),i,j;

    int str[3][3];

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

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

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

    cout<}return 0;}

  12. Anonymous users2024-01-27

    It's simple, for(i=0; i<3;i++)

    for(j=0;j<3;j++) Change j=0 to j=i+1.

  13. Anonymous users2024-01-26

    You changed it 2 times, and of course you changed it back again, hehe

    The for loop, which should be terminated when it is executed to t[1][1], is correct.

  14. Anonymous users2024-01-25

    It's to write a decimal to binary conversion.,Original format output.。

Related questions
8 answers2024-04-08

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

4 answers2024-04-08

2. 1, True 2, False (there is only one program) 3, False (not necessarily) 4, True. >>>More

16 answers2024-04-08

Definition of a for loop.

for(the initial value of the variable; termination of operating conditions; The initial value of the first cycle i is 0, and it runs until i=3 stops i=2, and the condition is still satisfied, and the loop body is still executed, and the step size is 1+1 each time >>>More

9 answers2024-04-08

Hey! This is a very simple function to write, Your Excellency is estimated to have just learned data structures, now learn sorting, lookup, it's easy to give me a reward of two hundred points, I'll help you write it right away. >>>More

8 answers2024-04-08

I thought about it for a long time and didn't come up with it. >>>More