#include <stdlib.h> #include <iostream> #include <iomanip> using namespace std;
int main() { double b[100][100]; int m,n; cout << "m = "; cin >> m; cout << "n = "; cin >> n; double min, s=0;
srand(time(0)); for (int i = 0; i < m; i++){ for (int j = 0; j < n; j++){ b[i][j]=-20 + (101.0 / RAND_MAX) * rand(); cout << fixed << setw (7) << setprecision (2) << b[i][j]; } cout <<endl; } for (int i = 0; i < m; i++){ min = b[i][0]; for (int j = 1; j < n; j++) if (b[i][j]<min) min=b[i][j]; s+=min; } cout << "s = " << s << endl; }
Пример: m = 4 n = 5 13.22 57.79 50.37 28.83 8.94 48.01 32.86 -16.49 -5.80 67.08 15.84 26.60 42.95 -0.34 46.37 10.89 -3.28 0.48 -11.50 77.09 s = -19.39
vovlyur
31.03.2020
Var a: array[1..10] of integer; b: array[1..10] of real; i,n: integer; s: real; begin s:=0; n:=0; write('массив a: '); for i:=1 to 10 do begin read(a[i]); if a[i]<0 then begin s:=s+a[i]; n:=n+1; end; write(a[i],' '); end; s:=s/n; writeln; writeln('среднее арифметическое отрицательных: ',s); writeln('количество отрицательных: ',n); write('массив b: '); for i:=1 to 10 do begin if a[i]<0 then b[i]:=s else b[i]:=a[i]; write(b[i]:7:3); end; end.