Advertisement
patryk178

Untitled

Feb 14th, 2021
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define SIZE 5
  5.  
  6.  
  7. int main()
  8. {
  9.     int tab[SIZE][SIZE];
  10.     int max[SIZE][4];
  11.     printf("Podaj elementy: \n");
  12.     for(int i = 0;i<SIZE;i++)
  13.     {
  14.  
  15.         for(int j=0;j<SIZE;j++)
  16.         {
  17.             if(!scanf("%d",&tab[i][j]))
  18.             {
  19.                 printf("Incorrect input");
  20.                 return 1;
  21.             }
  22.         }
  23.     }
  24.  
  25.  
  26.     int max_val = tab[0][0] + tab[0][1];
  27.  
  28.     for(int i=0;i<SIZE;i++)
  29.     {
  30.         for(int j=0;j<SIZE;j++)
  31.         {
  32.             for(int k=0;k<SIZE;k++)
  33.             {
  34.                 for(int l=0;l<SIZE;l++)
  35.                 {
  36.                     if(tab[i][j]+tab[k][l] > max_val && !(i==k && j==l)&& SIZE*i+j<SIZE*k+l )max_val = tab[i][j]+tab[k][l];
  37.                 }
  38.             }
  39.         }
  40.     }
  41.  
  42.     int count = 0;
  43.     for(int i=0;i<SIZE;i++)
  44.     {
  45.         for(int j=0;j<SIZE;j++)
  46.         {
  47.             for(int k=0;k<SIZE;k++)
  48.             {
  49.                 for(int l=0;l<SIZE;l++)
  50.                 {
  51.                     int x = tab[i][j]+tab[k][l];
  52.                     //int x = 0;
  53.                     if(x == max_val && !(i==k && j==l)&& SIZE*i+j<SIZE*k+l)
  54.                     {
  55.                         max[count][0] = i;
  56.                         max[count][1] = j;
  57.                         max[count][2] = k;
  58.                         max[count][3] = l;
  59.                         count++;
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.     }
  65.  
  66.  
  67.     printf("%d %d\n",max_val,count);
  68.     for(int i=0;i<count;i++)
  69.     {
  70.         printf("%d %d %d %d\n",max[i][0],max[i][1],max[i][2],max[i][3]);
  71.     }
  72.  
  73.  
  74.     return 0;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement