Advertisement
SergeyPGUTI

8.2.12

Feb 19th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string.h>
  4. #include<cstdlib>
  5. #include<ctime>
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     int n,m,temp,nullCounter,rnd;
  14.     srand((unsigned)time(0));
  15.     cin>>n;
  16.     cin>>m;
  17.     int **p= new int*[n];
  18.  
  19.     for (int i=0;i<n;i++)
  20.     {
  21.         p[i]=new int[m];
  22.     }
  23.  
  24.     for (int i=0;i<n;i++)
  25.         for (int j=0;j<m;j++)
  26.         {
  27.             rnd=rand()%100;
  28.             if (rnd>50)
  29.                 p[i][j]=0;
  30.             else
  31.                 p[i][j]=rnd;
  32.         }
  33.  
  34.  
  35.  
  36.      for (int i=0;i<n;i++)
  37.     {
  38.  
  39.         for (int j=0;j<m;j++)
  40.             {
  41.                 cout.width(3);
  42.                 cout<<p[i][j]<<" ";
  43.             }
  44.             cout<<endl;
  45.     }
  46. cout<<endl;cout<<endl;cout<<endl;
  47.  
  48.     nullCounter=0;
  49.     for (int i=0;i<n;i++)
  50.         for (int j=0;j<m;j++)
  51.         {
  52.             if (p[i][j]==0) nullCounter++;
  53.         }
  54.     cout<<nullCounter;
  55.  
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement