Hello i cant finish my code. What i basically need to do is (this is a rough transaltion to english)
Is make a A[4][7] matrix , then get the columns 4,5,6,7 displayed on the screen and then i need to somehow make the colums add up the numbers in the to a sum. For example the coulm for may have numbers 53,213,421,232 so my programm needs to add them all up 53+213+421+232=917, and like that with EACH of the columns.
I have manuaged to somehow make the matrix , get each of the columns displayed on the screen but i have no clue how to make it add them up to a sum.
This is what i manauged to make.
Also i was hinted that i should add
Is make a A[4][7] matrix , then get the columns 4,5,6,7 displayed on the screen and then i need to somehow make the colums add up the numbers in the to a sum. For example the coulm for may have numbers 53,213,421,232 so my programm needs to add them all up 53+213+421+232=917, and like that with EACH of the columns.
I have manuaged to somehow make the matrix , get each of the columns displayed on the screen but i have no clue how to make it add them up to a sum.
This is what i manauged to make.
Also i was hinted that i should add
int nTotal = 0;and after that put
(nTotal += maatriks[i][3]);in a loop somewhere? i didnt understand any of that.....
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define RIDU 4
#define VEERGE 7
#define MAX 150
#define MIN 10
int main (void)
{
int maatriks [RIDU] [VEERGE];
int i,j;
srand(time(NULL));
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
maatriks[i][j]=rand()%(MAX-MIN)+MIN;
}
}
printf("Generated matrix is :\n\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
printf("%4d", maatriks[i][j]);
}
printf("\n\n");
}
printf("========================================\n");
printf("Colums from the third to the right\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
if (j>2) printf("%4d", maatriks[i][j]);
}
printf("\n");
}
printf("========================================\n");
for(i=0; i<RIDU; i++)
{
}
printf("Fourth column and its sum\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
(nTotal += maatriks[i][3]);
if (j<1) printf("%4d", maatriks[i][3]);
}
printf("\n");
}
printf("----------------------------------------\n");
printf("Fourth column and its sum\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
if (j<1) printf("%4d", maatriks[i][4]);
}
printf("\n");
}
printf("----------------------------------------\n");
printf("Fifth column and its sum\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
if (j<1) printf("%4d", maatriks[i][5]);
}
printf("\n");
}
printf("----------------------------------------\n");
printf("sixth column and its sum\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
if (j<1) printf("%4d", maatriks[i][6]);
}
printf("\n");
}
printf("----------------------------------------\n");
scanf("%d");
return 0;
}