K
K
kraz123452018-10-13 18:52:11
C++ / C#
kraz12345, 2018-10-13 18:52:11

How to make the program drive the minimum?

It is necessary that the program displays the minimum diagonally to the selected cell, it must be done for all cells.
I get all units, how can I fix it? Please help, otherwise the 3rd day is some kind of blunt

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int a[5][5],k,n,m,l,p,q,x;
int main()
{int i,j,min,max;
printf("Vvedite n i m\n");
scanf("%d%d",&n,&m);
printf("Vvedite massiv\n");
for (i = 0; i <n; i++)
  {for (j = 0; j <m; j++)
      {
      scanf("%d",&a[i][j]);
      }
  }
printf("min\n");
for (p=0;p<n;p++)
    {for (q=0;q<m;q++)
      {

        min=a[0][0];
        max=0;
        if (p>q){l=q;}
        if (p<q){l=p;}
        if (p==q){l=p;}
        x=p;
        j=q;
        for(i=0;i<l;i++)
          {
          if (a[x][j]<min){min=a[x][j];}
        x--;
        j--;}
        printf("%5d\n",min);}}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2018-10-13
@res2001

You are too smart. I give only the cycle for calculating the minimum along the diagonal:

min = a[0][0];
for (p=1;p<n && p<m;p++) {
       if (a[p][p]<min) {
          min=a[p][p];
       }
}
printf("%5d\n",min);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question