1. const n=12; var a:array[1..n] of integer; i,max,imax,min,imin:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin a[i]:=Random(51)+150; Write(a[i]:4) end; writeln; max:=a[1]; imax:=1; min:=a[1]; imin:=1; for i:=2 to n do begin if a[i]>max then begin max:=a[i]; imax:=i; end; if a[i]<min then begin min:=a[i]; imin:=i; end; end; Writeln('max = a[',imax,'] = ',max,', min = a[',imin,'] = ',min); end.
2. const n=20; var a:array[1..n] of integer; i,j,c:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin a[i]:=Random(51)-25; Write(a[i],' ') end; Writeln; for i:=1 to n div 2-1 do for j:=1 to n div 2-i do if a[j]>a[j+1] then begin c:=a[j]; a[j]:=a[j+1]; a[j+1]:=c end; Writeln('Измененный массив:'); for i:=1 to n do Write(a[i],' '); Writeln end.
#include <iostream> #include <stdio.h> using namespace std;
int main(){ int y; cin>>y; y=y%12; switch (y){ case 4:{cout<<"Mouse"; break;} case 5:{cout<<"Bull";break;} case 6:{cout<<"Tiger";break;} case 7:{cout<<"Rabbit";break;} case 8:{cout<<"Dragon";break;} case 9:{cout<<"Snake";break;} case 10:{cout<<"Horse";break;} case 11:{cout<<"Goat";break;} case 0:{cout<<"Monkey";break;} case 1:{cout<<"Cock";break;} case 2:{cout<<"Dog";break;} case 3:{cout<<"Pig";break;} } cin.get(); cin.get(); return 0; }
const n=12;
var
a:array[1..n] of integer;
i,max,imax,min,imin:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do begin
a[i]:=Random(51)+150;
Write(a[i]:4)
end;
writeln;
max:=a[1]; imax:=1;
min:=a[1]; imin:=1;
for i:=2 to n do
begin
if a[i]>max then begin max:=a[i]; imax:=i; end;
if a[i]<min then begin min:=a[i]; imin:=i; end;
end;
Writeln('max = a[',imax,'] = ',max,', min = a[',imin,'] = ',min);
end.
Пример:
Исходный массив:
170 165 194 186 165 161 174 172 177 191 158 181
max = a[3] = 194, min = a[11] = 158
2.
const n=20;
var
a:array[1..n] of integer;
i,j,c:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do begin
a[i]:=Random(51)-25;
Write(a[i],' ')
end;
Writeln;
for i:=1 to n div 2-1 do
for j:=1 to n div 2-i do
if a[j]>a[j+1] then
begin c:=a[j]; a[j]:=a[j+1]; a[j+1]:=c end;
Writeln('Измененный массив:');
for i:=1 to n do Write(a[i],' ');
Writeln
end.
Пример:
Исходный массив:
16 3 1 18 10 -12 -23 19 -5 -5 0 10 13 14 17 14 6 22 25 -22
Измененный массив:
-23 -12 -5 -5 1 3 10 16 18 19 0 10 13 14 17 14 6 22 25 -22
#include <stdio.h>
using namespace std;
int main(){
int y;
cin>>y;
y=y%12;
switch (y){
case 4:{cout<<"Mouse"; break;}
case 5:{cout<<"Bull";break;}
case 6:{cout<<"Tiger";break;}
case 7:{cout<<"Rabbit";break;}
case 8:{cout<<"Dragon";break;}
case 9:{cout<<"Snake";break;}
case 10:{cout<<"Horse";break;}
case 11:{cout<<"Goat";break;}
case 0:{cout<<"Monkey";break;}
case 1:{cout<<"Cock";break;}
case 2:{cout<<"Dog";break;}
case 3:{cout<<"Pig";break;}
}
cin.get();
cin.get();
return 0;
}