Commit 2097d10f by raliis

Maatriksi diagonaalide ülesanne

parent 28d650e8
Showing with 41 additions and 0 deletions
#include <stdio.h>
int n=4; int m=4; //maatriksi mőődud
int A[4][4]={{-3,2,7,9},{6,-3,12,5},{3,7,7,8},{5,2,1,0}};
int Summa1 = 0;
int Summa2 = 0;
int a; int b; int x; int y;
int main(void){
int Summa1 = 0;
int a=0;
int b=0;
while(a<m){
if(a==b && A[a][b]>0){
Summa1 = Summa1 + A[a][b];
}
b++;
a++;
}
int Summa2 = 0;
int x=0;
int y=3;
while(x<m){
if(x+y==3){
Summa2 = Summa2 + A[x][y];
}
y--;
x++;
}
if(Summa1 > Summa2){
printf("Diagonaalide summad on: %d ja %d", Summa1, Summa2);
}else{
printf("Diagonaalide summad on: %d ja %d", Summa2, Summa1);
}
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