Write program two and run it to find the sum of all the elements on two diagonal lines of a 4 4 matr

Updated on technology 2024-02-27
5 answers
  1. Anonymous users2024-02-06

    The ** provided is mainly based on the following two errors:

    1. If you want to initialize a 4*4 matrix by assigning values, you need to loop in two layers.

    instead of writing "scanf(" on a separate line"%d",&a[i][j]);Only one element will be recorded.

    2. if(i=j) is wrong, it should be "==". in the C language.

    It is best to use {} to reconcile hierarchical relationships.

    The modified ** is as follows:

    #include<

    int main()

    int s,a[4][4],i=0,j=0;

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

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

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

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

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

    if(i==j)

    s=s+a[i][j];

    if(i+j==3)

    s=s+a[i][j];

    printf("%d",s);

    return 0;

    The following figure shows the result.

  2. Anonymous users2024-02-05

    In the fourth line, ints is changed to int s, one less space, and the input is not correct, scanf should be placed in the for loop, and the initial value of s should be assigned 0, so many mistakes ==

  3. Anonymous users2024-02-04

    The ** provided is mainly based on the following two errors:

    1. If you want to initialize the 4*4 matrix by way of assignment, you need to write the scanf statement in the two-layer for loop, instead of writing "scanf(" on a separate line"%d",&a[i][j]);Only one element will be recorded.

    2. if(i=j) error, it should be "==In the writing of C language, it is best to use {} to regulate the hierarchical relationship.

    The modified ** is as follows:

    #include

    int main()

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

    printf("%d",s);

    return 0;

    The following figure shows the result.

  4. Anonymous users2024-02-03

    The ** provided is mainly based on the following two errors:

    1. If you want to initialize the 4*4 matrix by way of assignment, you need to write the scanf statement in the two-layer for loop, instead of writing "scanf(" on a separate line"%d",&a[i][j]);Only one element will be recorded.

    2. if(i=j) error, it should be "==In the writing of C language, it is best to use {} to adjust the hierarchical relationship of pants.

    The modified ** is as follows:

    #include

    int main()

    int s,a[4][4],i=0,j=0;

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

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

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

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

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

    if(i==j)

    s=s+a[i][j];

    if(i+j==3)

    s=s+a[i][j];

    printf("%d",s);

    return 0;

    The result of pure delay in the operation of the file is shown in the figure below.

  5. Anonymous users2024-02-02

    Hello! In the fourth line, ints are changed to ints

    s, one less space, and the input is not right, scanf should be placed in the for loop, and the initial value of s should be assigned 0, so many mistakes ==

    If Jian Lumu has any questions, please ask. Barriers.

Related questions
5 answers2024-02-27

#include

#define m 5 >>>More

9 answers2024-02-27

This is a simple program controlled by a single button, you will ask such a question, indicating that you do not understand the timing analysis of the PLC enough, look at this example, first the external driver, closing, in the input image register to collect the closure, and then enter the program scanning stage, the scanning mode of the PLC should be known! Top-to-bottom, left-to-right, linear cyclic scanning. Then because of the closure of the scan, the first network can flow on, through, through the rising edge command, turn on the coil for a cycle of scanning time, that is to say, after scanning the self-locking contact, the coil loses power. >>>More

3 answers2024-02-27

If you want the source**, I can make one and send it to you. >>>More