Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     const int WMAX=100;
  8.     const int ZMAX=100;
  9.     float A[WMAX][ZMAX];
  10.     int m, n;
  11.  
  12.  
  13.  
  14.     cout<<" Podaj liczbe wierszy <="<<WMAX<<": "<<endl;
  15.     cin>>m;
  16.     cout<<" Podaj liczbe kolumn: <="<<ZMAX<<": "<<endl;
  17.     cin>>n;
  18.     cout<<endl;
  19.  
  20.     for (int i=0; i<m;i++)
  21.     {
  22.         for (int j=0;j<n;j++)
  23.         {
  24.             cout<<"Podaj wyraz ["<<i+1<<"],["<<j+1<<"]: ";
  25.             cin>>A[i][j];
  26.                     }
  27.     }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.     //teraz wyczytanie tej tablicy
  38.     for (int i=0; i<m;i++)
  39.     {
  40.         for (int j=0;j<n;j++)
  41.         {
  42.             cout<<"["<<i+1<<"],["<<j+1<<"]: "<<A[i][j]<<"  ";
  43.             }
  44.             cout<<endl;
  45.     }
  46.  
  47.     //srednia arytmetyczna liczb dodatnich tej macierzy
  48.  
  49.  
  50.     float suma;
  51.     suma=0;
  52.     int p;
  53.     p=0;
  54.     float srednia;
  55.  
  56.     for (int i=0; i<m;i++)
  57.     {
  58.         for (int j=0;j<n;j++)
  59.         {
  60.             if ( (A[i][j])>0)
  61.                suma+=A[i][j];
  62.                p++;
  63.                     }
  64.     }
  65.     srednia=suma/p;
  66.     cout<<"Srednia liczb dodatnich tej macierzy wynosi: "<<srednia<<". "<<endl;
  67.  
  68.  
  69.     //suma elementow zacyznjacych sie na liczbe dodatnia
  70.  
  71. float sumax;
  72.     sumax=0;
  73.     int r;
  74.     r=0;
  75.     float sredniax;
  76.  
  77. for (int i=0; i<m;i++)
  78.     {
  79.         if ((A[i][0])>0)
  80.         {
  81.             for (int j=0;j<n;j++)
  82.               {
  83.                 sumax+=A[i][j];
  84.                 r++;
  85.                         }
  86.         }
  87.     }
  88.  sredniax=sumax/r;
  89.  cout<<"Suma elementow macierzy ktore leza w wierszach zaczynjacych sie liczba dodatnia wynosi: "<<sredniax<<". "<<endl;
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  //wektor ktorego elementami sa najwieksze z poszczegolnych kolumn
  98. // :<<<<<<<
  99.  
  100. const int MA=100;
  101. float maksimum;
  102. maksimum=0;
  103. float B[MA];
  104.  
  105. for (int j=0;j<n;j++)
  106. {
  107.     for (int i=0;i<m-1;i++)
  108.     {
  109.         if (A[i][j]>maksimum)
  110.             maksimum=A[i][j];
  111.     }
  112.     B[j]=maksimum;
  113.     maksimum=0;
  114. }
  115.  
  116. for (int j=0;j<n;j++)
  117. cout<<B[j]<<"  ";
  118.  
  119. cout<<endl;
  120. cout<<endl;
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.     //suma pierwszego i ostatniego wiersza
  128.  
  129. const int DMAX=100;
  130. float D[DMAX];
  131.  
  132.     for (int j=0;j<n;j++)
  133.     {
  134.         D[j]= A[0][j]+A[n-1][j]     ;
  135. cout<<D[j]<<"   ";
  136.     }
  137.  
  138.  
  139.     return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement