0
ramz
4y

Hi everyone, I have such a task: “Given an integer square matrix. Determine the minimum among the sums of diagonal elements parallel to the main diagonal of the matrix.” I have a code but I have problems compiling a flowchart for it, can you help me with compiling a flowchart or give tips? thanks in advance!
Thats my code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N_MIN -3
#define N_MAX 5
int main(int argc, char *argv[]){
int s,i,j,k,l,s1,t2,t1;
int a[5][5];
srand(time(NULL));
for(i=0;i<5;i++){
for(j=0;j<5;j++){
a[i][j]=rand()%(N_MAX-N_MIN+1)+N_MIN;
}
}
for(i=0;i<5;i++){
for(j=0;j<5;j++){
printf("%3d ",a[i][j]);
}
printf("\n");
}
k=0;
s=0;
l=0;
for (i=0; i<5; i++){
for (j=0; j<5; j++){
if (a[i][j]>=0){
if(a[i][j]%2==0)
l+=a[i][j];
k++;
}
}
if (k==5){
l=l;
}
else {
l=0;
}
s=s+l;
k=0;
}
s1=a[0][5-1];
for(i=1; i<5; i++){
t1=t2=0;
for(j=0; j<5-i; j++){
t1+=a[i+j][j];
t2+=a[j][i+j];
}
if(t1<s1) s1=t1;
if(t2<s1) s1=t2;
}
printf("vivod %d %d\n", s,s1);
return 0;
}

Comments
Add Comment