SHARE
TWEET

Untitled

Kosrotoff Nov 14th, 2019 104 in 5 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3.  
  4. using std::cin;
  5. using std::cout;
  6.  
  7.  
  8. bool isPrime(int n)
  9. {
  10.     for (int d = 2; d <= sqrt(n); d++) {
  11.         if (n % d == 0) {
  12.             return false;
  13.         }
  14.     }
  15.     return (n > 1);
  16. }
  17.  
  18. int main()
  19. {
  20.     setlocale(LC_ALL, "Russian");
  21.  
  22.     int n, m;
  23.     double A[100][100];
  24.  
  25.     cout << "Число строк: ";
  26.     cin >> n;
  27.     cout << "Число столбцов: ";
  28.     cin >> m;
  29.  
  30.     cout << "Матрица:\n";
  31.     for (int i = 0; i < n; i++) {
  32.         for (int j = 0; j < m; j++) {
  33.             cin >> A[i][j];
  34.         }
  35.     }
  36.     cout << '\n';
  37.  
  38.     for (int j = 0; j < m; j++) {
  39.         double sumPrime = 0;
  40.         double sumComposite = 0;
  41.         int countPrime = 0;
  42.  
  43.         for (int i = 0; i < n; i++) {
  44.             sumPrime += A[i][j] * isPrime(A[i][j]);
  45.             sumComposite += A[i][j] * !isPrime(A[i][j]);
  46.             countPrime += isPrime(A[i][j]);
  47.         }
  48.         if (j % 2 == 0) {
  49.             A[0][j] = sumPrime / countPrime;
  50.         }
  51.         else {
  52.             A[0][j] = sumComposite / (n - countPrime);
  53.         }
  54.     }
  55.  
  56.     cout << "Результат:\n";
  57.     for (int i = 0; i < n; i++) {
  58.         for (int j = 0; j < m; j++) {
  59.             cout << A[i][j] << ' ';
  60.         }
  61.         cout << '\n';
  62.     }
  63.  
  64.     return 0;
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top