Advertisement
o_paulooo

Matriz L01E07

Nov 13th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.22 KB | None | 0 0
  1. /*
  2. 7- Um elemento Aij de uma matriz é dito PONTO DE SELA da matriz A se, e somente se, Aij for ao
  3. mesmo tempo o MENOR elemento da linha i e o MAIOR elemento da coluna j. Faça um programa
  4. que receba uma matriz de ordem 50x70. Ao final da entrada, limpar a tela, mostrar a matriz,
  5. verificar se a matriz possui ponto de sela, e se possuir, mostrar o valor do elemento e sua
  6. localização (qual linha e coluna).
  7. */
  8.  
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <locale.h>
  12. #define t 2
  13. #define u 2
  14.  
  15. void zerar(int m[][u])
  16. {
  17.     int i, j;
  18.  
  19.     for(i=0; i<t; i++)
  20.     {
  21.         for(j=0; j<u; j++)
  22.             m[i][j] = 0;
  23.     }
  24. }
  25.  
  26.  
  27. void receber(int m[][u])
  28. {
  29.     int i, j;
  30.  
  31.     for(i=0; i<t; i++)
  32.     {
  33.         for(j=0; j<u; j++)
  34.         {
  35.             printf("Digite o valor para M[%d][%d]: ", i+1, j+1);
  36.             scanf("%d", &m[i][j]);
  37.         }
  38.     }
  39. }
  40.  
  41.  
  42. void mostrar_m(int m[][u])
  43. {
  44.     int i, j;
  45.  
  46.     for(i=0; i<t; i++)
  47.     {
  48.         for(j=0; j<u; j++)
  49.             printf("%4d", m[i][j]);
  50.  
  51.         printf("\n\n");
  52.     }
  53. }
  54.  
  55. int main()
  56. {
  57.     setlocale(LC_ALL, "portuguese");
  58.  
  59.     int m1[t][u], sel, aux, cont, l1, l2, c1, c2, i, j, k;
  60.     l1 = l2 = c1 = c2 = cont = 0;
  61.  
  62.     zerar(m1);
  63.  
  64.     printf("\n\n");
  65.     receber(m1);
  66.  
  67.  
  68.  
  69.     printf("\n\n");
  70.     printf("\n\n\nA matriz A: \n\n");
  71.     mostrar_m(m1);
  72.  
  73.     for(i=1; i<t; i++)                              // >l
  74.     {
  75.         aux = m1[i][0];
  76.  
  77.         for(j=1; j<u; j++)
  78.         {
  79.             if(aux > m1[i][j])
  80.             {
  81.                 aux = m1[i][j];
  82.                 l1 = i+1;
  83.                 c1 = j+1;
  84.             }
  85.  
  86.             sel = m1[0][j];
  87.  
  88.             for(k=1; k<t; k++)                          //<c
  89.             {
  90.                 if(sel < m1[k][j])
  91.                 {
  92.                     sel = m1[k][j];
  93.                     l2 = k+1;
  94.                     c2 = j+1;
  95.                 }
  96.             }
  97.  
  98.             if(aux == sel)
  99.             {
  100.                 printf("Ponto de sela %d é: %d, localizado em %d,%d", i+1, sel, l1, c1);
  101.                 cont++;
  102.             }
  103.         }
  104.  
  105.     }
  106.  
  107.     if(cont == 0)
  108.         printf("Não há ponto de sela!!!");
  109.  
  110.     printf("\n\n\n\n\n");
  111.  
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement