A
A
Andrey Rudenko2020-12-17 22:11:11
C++ / C#
Andrey Rudenko, 2020-12-17 22:11:11

How to find the sum of an array column (convert from a string to a search for the sum of a column)?

Good evening. You need to pass the code to the search for the sum of the column (I have a search from the row), you don’t need to remove the procedure, thanks for the help!

#include <stdio.h>

int suma(int *T, int line){
    int sum = 0;
    for (int j = 0; j < 4; j++) {
        sum += T[j];
    }
    return sum;
}

int main() {
    int T[4][4] = {{4, 5, 1,  7 },
                   {1, 8, -2,  2 },
                   {8, 5, 12,  -7},
                   {6, 4, -3, 6 }};

    for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                printf("%d\t", T[i][j]);
            }
            printf("\n");
    }
    for (int i = 0; i < 4; i++) {
        printf("\nРядок - %d сума - %d",i, suma(&T[i],i));
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2020-12-17
@FlapsBat

Here:

#include <stdio.h>

int suma(int T[4][4], int i){
    int sum = 0;
    for (int j = 0; j < 4; j++) {
        sum += T[j][i];
    }
    return sum;
}

int main() {
    int T[4][4] = {{4, 5, 1,  7 },
                   {1, 8, -2,  2 },
                   {8, 5, 12,  -7},
                   {6, 4, -3, 6 }};

    for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                printf("%d\t", T[i][j]);
            }
            printf("\n");
    }
    for (int i = 0; i < 4; i++) {
      printf("\nСтолбец - %d сума - %d", i, suma(T, i));
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question