Pascal: var a:array [1..5] of integer; i:integer; begin randomize; for i:=1 to 5 do begin a[i]:=random(31)-15; write (a[i]:4); end; writeln; for i:=1 to 5 do begin a[i]:=a[i]*2; write (a[i]:4); end; writeln; readln; end.
C++: #include <iostream> #include <ctime> #include <cstdlib> using namespace std;
int main() { int a[5]; srand (time(NULL)); for (int i = 0; i<5; i++) { a[i] = rand()%15-15; cout <<a[i] <<" "; } cout <<endl; for (int i = 0; i<5; i++) { a[i]*=2; cout <<a[i] <<" "; } return 0; }
Pascal: var a:array [1..30] of integer; i:integer; p:longint; begin p:=1; randomize; a[1]:=random(21)+50; for i:=2 to 29 do a[i]:=random(100); a[30]:=random(21)+50; for i:=1 to 30 do write (a[i],' '); writeln; for i:=1 to 30 do if (a[i] in [10..99]) and (a[i] mod 2 = 0) and ((a[i] div 10) in [5..7]) then p:=p*a[i]; writeln ('Proizvedenie: ',p); readln; end.
C++: #include <iostream> #include <ctime> #include <cstdlib> using namespace std;
int main() { int a[30],i; unsigned long long p = 1; srand (time(NULL)); a[0] = rand()%70+50; for (i = 1; i<29; i++) a[i] = rand()%100; a[29] = rand()%7+50; for (i = 0; i<30; i++) { cout <<a[i] <<" "; if ((a[i]/10==5 || a[i]/10==6 || a[i]/10==7) && (a[i]>9 && a[i]<100) && a[i]%2==0) p*=a[i]; } cout <<endl; cout <<"Proizvedenie: " <<p <<endl; return 0; }
144 : 4= 36
после запятой позиции цифр: (период начинается со 2-ой позиции)
1 2 3 4 5 142 143 144 145
3 7 2 4 9 7 2 4 9
ответ 4