Напишите программу, которая вводит натуральное число n и выводит на экран чётные положительные степени числа 2, не большие, чем n , в порядке убывания.
Var n,k,m: integer; begin write('число: '); readln(n); m:=1; k:=trunc(log2(n)); if (k mod 2)=1 then m:=m shl (k-1) else m:=m shl k; repeat write(m,' '); m:=m shr 2; until m<2; end.
ldstroy
13.12.2021
#include <iostream> #include <cstdlib>
using namespace std;
int main() { int i,j; int a[4][3]; for (i=0; i<4; i++){ cout<<"Stroka "<<i+1<<endl; for (j=0; j<3; j++) { cout<<"Element "<<j+1<<": "; cin>>a[i][j]; } cout<<endl; } cout<<"Resul'tat"<<endl; for (i=0; i<4; i++) { for (j=0; j<3; j++) { a[i][j]*=a[i][j]; cout<<a[i][j]<<" "; } cout<<endl; } cin>>i; //ïðîñòî ÷òîáû ýêðàí íå çàêðûëñÿ return 0; }
Тестовое решение (Dev C++) Stroka 1 Element 1: 1 Element 2: 2 Element 3: 3
Stroka 2 Element 1: 4 Element 2: 5 Element 3: 6
Stroka 3 Element 1: 7 Element 2: 8 Element 3: 9
Stroka 4 Element 1: 10 Element 2: 11 Element 3: 12
Resul'tat 1 4 9 16 25 36 49 64 81 100 121 144:
Avetisyan575
13.12.2021
Const n = 15;
var x: array[1..n] of integer; i, b, s: integer;
begin Randomize; Writeln('Элементы массива'); for i := 1 to n do begin x[i] := Random(50); Write(x[i]:3); end; Writeln; Write('Введите значение b -> '); Readln(b); s:=0; for i := 1 to n do if x[i]>b then s:=s+b; Writeln('Сумма элементов, больших ',b,', равна ',s) end.
Тестовое решение: Элементы массива 8 46 29 23 21 14 14 8 20 26 15 49 44 35 33 Введите значение b -> 30 Сумма элементов, больших 30, равна 150
const n = 15;
var x: array[1..n] of integer; i, b: integer;
begin Randomize; Writeln('Элементы массива'); for i := 1 to n do begin x[i] := Random(50); Write(x[i]:3); end; Writeln; Write('Введите значение b -> '); Readln(b); i:=1; while (x[i]<>b) and (i<n) do Inc(i); if x[i]=b then Writeln('x[',i,']=',b) else Writeln('Нет элементов со значением, равным ',b) end.
Тестовое решение: Элементы массива 24 6 28 46 25 9 12 47 34 0 20 47 15 10 34 Введите значение b -> 20 x[11]=20
begin
write('число: '); readln(n);
m:=1;
k:=trunc(log2(n));
if (k mod 2)=1 then m:=m shl (k-1)
else m:=m shl k;
repeat
write(m,' ');
m:=m shr 2;
until m<2;
end.