KvArt

Untitled

Apr 20th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. #define MAX 15
  5.  
  6. main()
  7. {
  8.     int a[MAX][MAX], n, m, i, j, x, y, top, bot, izbor = 0;
  9.     srand(time(NULL));
  10.     while (1)
  11.     {
  12.         printf("\nUnesite broj redova matrice: ");
  13.         scanf("%d", &n);
  14.         if (n <= 0)break;
  15.             printf("\nUnesite broj kolona matrice: ");
  16.             scanf("%d", &m);
  17.             if (m <= 0)break;
  18.             printf("\n\nDa li zelite da popunite matricnu rucno(1) ili zelite da se popuni random brojevima(2)");
  19.                 printf("\n\nVas izbor: ");
  20.                 scanf("%d", &izbor);
  21.                 switch (izbor)
  22.                 {
  23.                 default: printf("\nMolim vas izaberite izmedju '1' i '2'\n"); break;
  24.                
  25.                 case 1:
  26.                     for (i = 0; i < n; i++)
  27.                         for (j = 0; j < m; j++)
  28.                         {
  29.                             printf("\nUnesite element a[%d][%d]: ", i, j);
  30.                             scanf("%d", &a[i][j]);
  31.                             printf("\nIzgled vase matrice je");
  32.                             printf("\n\n");
  33.                         }
  34.                     for (i = 0; i < n; i++)
  35.                     {
  36.                         for (j = 0; j < m; j++)
  37.                             printf("\t%5d", a[i][j]);
  38.                         printf("\n\n");
  39.                     }break;
  40.                
  41.                 case 2:
  42.                     printf("\nUnesie donju granicu opsega random brojeva: ");
  43.                     scanf("%d", &bot);
  44.                         printf("\nUnesie gornju granicu opsega random brojeva: ");
  45.                         scanf("%d", &top);
  46.                         printf("\nIzgled vase matrice je");
  47.                         printf("\n\n");
  48.                         for (i = 0; i < n; i++)
  49.                             for (j = 0; j < m; j++)
  50.                             {
  51.                                 a[i][j] = rand() / ((double)RAND_MAX)*(top - bot) + bot;
  52.                             }
  53.                         for (i = 0; i < n; i++)
  54.                         {
  55.                             for (j = 0; j < m; j++)
  56.                                 printf("\t%5d", a[i][j]);
  57.                             printf("\n\n");
  58.                         }break;
  59.                 }
  60.                 int max = a[x][y];
  61.                 int maxi = x, maxj = y;
  62.                 for (i = 0; i<n; i++)
  63.                 {
  64.                     if (a[i][y]>max)
  65.                         maxi = i;
  66.                 }
  67.                 for (j = 0; j<m; j++)
  68.                 {
  69.                     if (a[x][j]>max)
  70.                         maxj = j;
  71.                 }
  72.                 if (maxi == x&&maxj == y)
  73.                     printf("\nMaksimalni: ");
  74.                 for (i = 0; i<n; i++)
  75.                 {
  76.                     for (j = 0; j<n; j++)
  77.                     {
  78.                         int max = a[x][y];
  79.                         int maxi = x, maxj = y;
  80.                         printf("\t%5d", a[i][j]);
  81.                     }
  82.                 }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment