WSTI

8d_4

Dec 8th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. /* napisać funkcję, która wyznacza maksymalny element parzysty  dwuwymiarowej tablicy
  7.  liczb całkowitych o  liczbie kolumn M=7 i dowolnej liczbie wierszy;
  8. sprawdzić działanie funkcji;
  9. */
  10. int nep(int tab[][7], int size)
  11. {
  12.     int max=0;
  13.     int *wsk=&tab[0][0];
  14.  
  15.     for(int i=0; i<size; i++)
  16.     {
  17.         if(*(wsk+i)%2==0 && *(wsk+i)>max)
  18.             max = *(wsk+i);
  19.     }
  20.  
  21.     return max;
  22.  
  23. }
  24. int main()
  25. {
  26.     const int N=4, M=7;
  27.     int tab[N][M];
  28.  
  29.         for(int i=0; i<N; i++)
  30.             for(int k=0; k<M; k++)
  31.                 tab[i][k]=rand()%101;
  32.  
  33.     int size = sizeof(tab)/sizeof(int);
  34.  
  35.         cout << nep(tab, size) << endl;
  36.  
  37.     return 0;
  38. }
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment