max = a[0]+a[n-1]; min = a[0]*a[n/2]; for (int i = 1; i<n/2; i++){ if (a[i]+a[n-i-1] > max) max = a[i]+a[n-i-1]; if (a[i]*a[n/2+i] < min) min = a[i]*a[n/2+i]; } cout << "max = " << max << "\n"; cout << "min = " << min << "\n"; return 0; }
Пример (для n=10): -19.29 30.99 -15.37 26.41 3.65 13.45 29.28 4.28 30.51 -10.36 max = 61.50 min = -259.43
var
s: string;
i, count: integer;
begin
writeln('Vvedite stroky: ');
readln(s);
for i := 1 to length(s) - 2 do
if copy(s, i, 3) = 'abc' then
count := count + 1;
writeln('Kol-vo: ', count);
end.
2.
var
s1, s2: string;
i, len1, len2: integer;
begin
writeln('Vvedite stroky 1: ');
readln(s1);
writeln('Vvedite stroky 2: ');
readln(s2);
len1 := length(s1);
len2 := length(s2);
if len1 > len2 then writeln('1 stroka dlinnee')
else if len1 < len2 then writeln('2 stroka dlinnee')
else writeln('dlini strok ravnie')
end.
3.
var
s1, s2, s3: string;
begin
writeln('Vvedite stroky 1: ');
readln(s1);
writeln('Vvedite stroky 2: ');
readln(s2);
s3 := s1[1] + s1[2] + s2[1] + s2[2];
writeln('Novaja stroka: ', s3);
end.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
const int n = 30;
double a[n];
double max, min;
srand(time(0));
for (int i = 0; i < n; i++) {
a[i]=-20 + (51.0 / RAND_MAX) * rand();
cout << fixed << setw (7) << setprecision (2) << a[i];
}
cout <<"\n";
max = a[0]+a[n-1];
min = a[0]*a[n/2];
for (int i = 1; i<n/2; i++){
if (a[i]+a[n-i-1] > max) max = a[i]+a[n-i-1];
if (a[i]*a[n/2+i] < min) min = a[i]*a[n/2+i];
}
cout << "max = " << max << "\n";
cout << "min = " << min << "\n";
return 0;
}
Пример (для n=10):
-19.29 30.99 -15.37 26.41 3.65 13.45 29.28 4.28 30.51 -10.36
max = 61.50
min = -259.43