Commit 46f8391d by lilepp

tunnitoo4

parent fbd5b0b5
# Python v.3.6.2
n = 4
processRowsBefore = 2
# ---
A = [[2, 3, -4, 3],
[1, 2, 3, 0],
[1, 2, 3 ,4],
[1, 2, 3, 4]]
rowSums = []
for row in range(processRowsBefore -1):
rowSum = 0
for col in range(n):
if A[row][col] > 0:
rowSum += A[row][col]
rowSums.append(rowSum)
for i in range(len(rowSums)):
print(str(rowSums[i]))
#include <stdio.h>
int m = 3;
int n = 4;
int A[4][3]= {{5, -3, -12},{2, 3, -2},{1, -6, 8},{-4, -13, 4}};
void negSummad(void);
void trykiMaatriks(int n, int m, int[n][m]);
int main (void)
{
trykiMaatriks(n, m, A);
negSummad();
return 0;
}
void trykiMaatriks (int n, int m, int A[n][m])
{
int i=0;
int j=0;
while(i<n)
{
j=0;
while(j<m)
{
printf("%4d",A[i][j]);
j++;
}
printf("\n");
i++;
}
}
void negSummad(void)
{
int i=0;
int j=0 ;
int negsum[m];
printf("Tulpade negatiivsete elementide summad on: \n");
while (j<m)
{
i=0;
while(i<n)
{
if(A[i][j]<0) negsum[j]+=A[i][j];
i++;
}
printf("%4d", negsum[j]);
j++;
}
printf("\n%");
}
#include <studio.h>
int n=4; int m=3
int A[4][3]={{5, -3, -12},{2, 3, -2},{1, -6, 8},{-4, -13, 4}}
void negSummad(void);
void trykiMaatriks(int n, int m, int[n][m]);
int main (void)
{ trykiMaatriks(n, m, A);
negSummad(); return 0;
}
void trykiMaatriks (intn, int m, int A[n][m])
{int i=0;
int j=0
while(i<n) {
#include <stdio.h>
int main (void)
{
int n=4, m=4;
int i, j;
int A[4][4] = {{2, 3, -4, 3},
{1, 2, -3, 0},
{1, 2, 3, 4},
{1, 2, 3, 4}};
int rowSum[n];
for (i=0; i<n; i++)
{
rowSum[i]=0;
for(j = 0; j < m; j++)
{
if (A[i][j] > 0)
{
rowSum[i]+=A[i][j];
}
}
}
for (i = 0; i<n; i++)
{
printf("Maatriksi %d. rea summa on %d\n", i, rowSum[i]);
}
return 0;
}
#include <stdio.h>
int main (void)
{
int n = 4;
int m = 4;
int A[4][4] = {{-3, 2, 4, 3},
{6, -4, 2, 5},
{3, 7, 5, 8},
{2, 5, 3, 4}};
int peaSum = 0;
int i = 0;
int j = 0;
do
{
{
peaSum = peaSum + A[i][i];
}
i++;
// j++;
}while (i <= 4);
printf("Peasumma: %d\n", peaSum);
return 0;
}
#include <stdio.h>
int main (void)
{
int n = 4;
int m = 3;
int A[4][4] = {{-3, 2, 4, 3},
{6, -4, 2, 5},
{3, 7, 5, 8},
{2, 5, 3, 4}};
int peaSum = 0;
int i = 0;
int j = 0;
do
{
peaSum = peaSum + A[i][j];
i++;
j++;
}while (i <= 3);
printf("Peasumma: %d\n", peaSum);
i = 0;
j = m;
int kSum;
kSum = 0;
do
{
kSum = kSum + A[i][j];
i++;
j--;
} while(j>=0);
printf("Korvalsumma: %d\n", kSum);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment