Commit 8d3ccf60 by eglill

Tunnitöö4

parent 3b9c8ecf
Showing with 62 additions and 0 deletions
# Python v.3.6.2
# Eeldan, et sisendvaartustena kasutatakse vaid taisarve.
# kasutajale kuvatud indeksid on matemaatilised (algavad uhest)
# Ulesande tekstis antud vaartused
n=4
processRowsBefore=2
#--
# Algvaartustamine
A=[[2,3,-4,3],
[1,2,-3,0],
[1,2,3,4],
[1,2,3,4]]
# Rideade positiivsete elementide summa leidmine
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)
# Tulemuste valjastamine
for i in range(len(rowSums)):
print(str(rowSums[i]))
#include<stdio.h>
int main(void)
{
int n=4;
int rowSum[4];
int i=0;
int j=0;
int A[4][4]={{2,3,-4,3},
{1,2,-3,0},
{1,2,3,4},
{1,2,3,4}};
for (i=0; i<4; i++)
{
rowSum[i]=0;
for (j=0; j<n; j++)
{
if (A[i][j]>0)
{
rowSum[i] += A[i][j];
}
}
}
for (i=0; i<4; i++)
printf("%d \n", rowSum[i]);
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