Advertisement
KvArt

Untitled

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