Dodanie kolumny do istniejącej tablicy

0

mam program którego wynik wyświetlam w formacje tablicy. po czym obliczam sumę kolumn i wierszy które muszę wydrukować zgodnie po prawej sumę wierszy a pod spodem sumę kolumn z kolumnami to nie ma problemu ale z rzędami mam problem. Czy ktoś może mi coś podpowiedzieć
code

#include <stdio.h>

int main() {
    int i, j, sellsperson, product, sum_slipvalue, sum_productvalue, tab_sum[20][30], productivity[3][4];
    sellsperson = 0;
    product = 0;

    // filling in an array size of 20(representing [sellsperson][submitted slips]/per day)*30 (days of month)
    for (i = 0; i < 20; i++){
        for (j = 0; j < 30; j++){
            tab_sum[i][j] = rand()%100; // Dollar value of sold product for sells person(example from $0 to $100)
        }
    }
  
    for (i = 0; i < 20; i++){
        for (j = 0; j < 30; j++) {
            printf ("%d\t", tab_sum[i][j]);
        }
        printf ("\n");
    }

    //sum of cross product value by sellsperson
    for ( i = 0; i < 20; i++) {
        sum_slipvalue = 0;
        for ( j = 0; j < 30; j++) {
            sum_slipvalue += tab_sum[i][j];
        }
        productivity[sellsperson][product] = sum_slipvalue; //I'm assinging sum values to new array productivity

        if (!((product+1) % 5)) {
            sellsperson++;
            product = 0;
        }
        else product++;
    }

    printf ("\n");

    for (i = 0; i < 4; i++) {
        for(j = 0; j < 5; j++){
            printf ("%d\t", productivity[i][j]);
        }
        printf ("\n");
    }

    //sum of cross product value
    for ( i = 0; i < 4; i++) {
        sum_productvalue = 0;
        for ( j = 0; j < 5; j++) {
            sum_productvalue += productivity[i][j];
        }
        printf ("%d",sum_productvalue);
        printf (" \n");
    }

    //sum of cross product value by sellsperson
    for ( j = 0; j < 5; j++) {
        sum_productvalue = 0;
        for (i = 0; i < 4; i++){
            sum_productvalue += productivity[i][j];
        }
        printf ("%d\t", sum_productvalue);
    }

    printf ("\n");

    return 1;
}

int main() {
    int i, j, sellsperson, product, sum_slipvalue, sum_productvalue, tab_sum[20][30], productivity[3][4];
    sellsperson = 0;
    product = 0;

    // filling in an array size of 20(representing [sellsperson][submitted slips]/per day)*30 (days of month)
    for (i = 0; i < 20; i++){
        for (j = 0; j < 30; j++){
            tab_sum[i][j] = rand()%100; // Dollar value of sold product for sells person(example from $0 to $100)
        }
    }

    for (i = 0; i < 20; i++){
        for (j = 0; j < 30; j++) {
            printf ("%d\t", tab_sum[i][j]);
        }
        printf ("\n");
    }

    //sum of cross product value by sellsperson
    for ( i = 0; i < 20; i++) {
        sum_slipvalue = 0;
        for ( j = 0; j < 30; j++) {
            sum_slipvalue += tab_sum[i][j];
        }
        productivity[sellsperson][product] = sum_slipvalue; //I'm assinging sum values to new array productivity

        if (!((product+1) % 5)) {
            sellsperson++;
            product = 0;
        }
        else product++;
    }

    printf ("\n");

    for (i = 0; i < 4; i++) {
        for(j = 0; j < 5; j++){
            printf ("%d\t", productivity[i][j]);
        }
        printf ("\n");
    }

    //sum of cross product value
    for ( i = 0; i < 4; i++) {
        sum_productvalue = 0;
        for ( j = 0; j < 5; j++) {
            sum_productvalue += productivity[i][j];
        }
        printf ("%d",sum_productvalue);
        printf (" \n");
    }

    //sum of cross product value by sellsperson
    for ( j = 0; j < 5; j++) {
        sum_productvalue = 0;
        for (i = 0; i < 4; i++){
            sum_productvalue += productivity[i][j];
        }
        printf ("%d\t", sum_productvalue);
    }

    printf ("\n");

    return 1;
}
0

Przeformatuj ten kod... Daj znaczniki na 1. część i znaczniki cpp a nie code bo tego się nie da czytać!

// to anonim, nie może edytować swoich postów; poprawiłem za niego - Ł

0

tablica productivity jest za mała, powinno być

productivity[4][5]

lub zmniejsz zakres indexów po których ją przeszukujesz

1 użytkowników online, w tym zalogowanych: 0, gości: 1