Есть ответ 👍

Найти сумму максимального и минимального из 12 введенных чисел. вывести сами значения и их индексы.

241
345
Посмотреть ответы 3

Ответы на вопрос:


//pascalabs.net const n= 12; var a: array[1..n]of integer;       i,min,max,nmin,nmax: integer; begin   min: =99999;   max: =0;     for i: =1 to n do begin       readln(a[i]);       if a[i]> max then begin max: =a[i];           nmax: =i;       end;           if a[i]< min  then begin min: =a[i];           nmin: =i;       end;   end;     writeln ('сумма max+min ',max+min);   writeln ('максимальное ',max,' индекс', nmax);   writeln ('ммнимальное ',min,' индекс', nmin); end.

C++ #include< iostream> using namespace std; int main() {     int a[12],max,min,k=1,l=1;     for (i=1; i< =12; i++)     cin > >   a[i];     max = a[1];     min = max;     for (i=2; i< =12; i++)     {       if (a[i]  < =  min) { min = a[i]; k = i;   }       if (a[i] > = max)  {  max = a[i]; l = i; }     } cout < < "sum =  " < < min +max < < endl; cout < < "max =" < < max < < "   № "< < l < < endl; cout < < "min = " < < min < < "   № "< < k < < endl; }
Bsusb
4,4(84 оценок)

//pascal //1) var   a: array[1..5, 1..8] of integer;   i, j: byte;   sumr, sumc: integer; begin   randomize;   writeln('исходный массив': 28);   for i : = 1 to 5 do   begin       for j : = 1 to 8 do       begin           a[i, j] : = random(61)-30;           write(a[i,j]: 5);           if i = 3 then sumr : = sumr + a[i, j];           if j = 5 then sumc : = sumc + a[i, j];       end;   writeln;   end;   writeln('сумма элементов 5 столбца = ', sumc);   writeln('сумма элементов 3 строки = ', sumr); end. //2) var   a: array[1..5, 1..8] of integer;   i, j: byte;   suma, sumb, countv, countg: integer; begin   randomize;   writeln('исходный массив': 28);   for i : = 1 to 5 do   begin       for j : = 1 to 8 do       begin           a[i, j] : = random(300)-150;           write(a[i,j]: 5);           if ((i = 5) and (a[i, j] < 0)) then suma : = suma + a[i, j];           if ((j = 4) and (a[i, j] < 100)) then sumb : = sumb + a[i, j];           if ((i = 4) and (a[i, j] < 5)) then countv : = countv + 1;           if ((j = 2) and (a[i, j] > 15)) then countg : = countg + 1;       end;   writeln;   end;   writeln('сумма отрицательных 5 строки = ', suma);   writeln('сумма меньших 100 4-ого столбца = ', sumb);   writeln('количество меньших 5 4-ой строки = ', countv);   writeln('количество ненулевых, больших 15 2-ого столбца = ', countg); end.

Популярно: Информатика