Advertisement
niks32

146

Apr 16th, 2020
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "iostream"
  3.  
  4.  
  5. int _tmain(int argc, _TCHAR* argv[])
  6. {
  7.     setlocale(LC_ALL, "Russian");
  8.     std::cout << "Введите элементы массива (10 целых чисел) \"в одной строке\" и нажмите <Enter>." <<
  9.         std::endl;
  10.  
  11.     int numbers[10];
  12.     int *ptr_numbers = numbers;
  13.     int totalSum = 0;
  14.     int notNoolCounter = 0;
  15.  
  16.     for (int i = 0; i < 10; i++) {
  17.         std::cout << i + 1 << " -> ";
  18.         std::cin >> *(ptr_numbers + i);
  19.         totalSum = totalSum + *(ptr_numbers + i);
  20.         if (*(ptr_numbers + i) != 0) { notNoolCounter = notNoolCounter + 1; }
  21.     }
  22.  
  23.     std::cout << "Сумма элементов массива: " << totalSum << std::endl <<
  24.         "Количество ненулевых элементов: " << notNoolCounter << std::endl<<
  25.         "Среднее арифметическое ненулевых элементов: " << float(totalSum) / notNoolCounter <<
  26.         std::endl;
  27.    
  28.         system("pause");
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement