close

Вход

Забыли?

вход по аккаунту

?

lab3 (4)

код для вставкиСкачать
program Lab3;
{apptype console}// Консольное приложение
uses CRT;
var
i:longint;
j:longint;
k:longint;
sTabulator:string;
iProc01:longint;
//aProc11:array [0..21] of longint; //kinda useless ?!
iBuff11:longint;
iBuff12:longint;
aNumInput21:array [0..9] of longint;
aNumArr21:array [0..9] of longint;
iInputSize31:longint;
aMatrix31:array of array of longint;
iMaxBuff31:longint;
iMinBuff31:longint;
iMinCoord31:longint;
iMinCoord32:longint;
iMaxCoord31:longint;
iMaxCoord32:longint;
iInputSize41:longint;
aMainArr41:array of array of longint;
iProc41:longint;
iProc42:longint;
//iDebug41:longint; //ignore just debugging var
sTabulator41:string;
// Параметры меню
sMenuSelector:longint;// Селектор меню
sMenuString1:string;
sMenuString2:string;
sMenuString3:string;
sMenuString4:string;
sMenuString5:string;
sMenuString6:string;
sMenuString7:string;
begin
clrscr;
// Строки в меню
sMenuString1 := 'Select task:';
//sMenuString2 := '0. Hello world';
sMenuString3 := '1. Task 1';
sMenuString4 := '2. Task 2';
sMenuString5 := '3. Task 3';
sMenuString6 := '4. Task 4';
// Выводим меню
writeln(sMenuString1);
//writeln(sMenuString2);
writeln(sMenuString3);
writeln(sMenuString4);
writeln(sMenuString5);
writeln(sMenuString6);
writeln(sMenuString7);
readln(sMenuSelector); //Пользователь выбирает пункт
// Запускаем выбраное задание
if sMenuSelector = 0
then
begin
clrscr;
readln;
end
;
if sMenuSelector = 1
then
begin
clrscr;
iBuff11:= 1;
//iBuff12:= 2;
For i:= 0 to 20 do
begin
write('2^');
write(i);
write('=');
writeln(iBuff11);
iBuff11:= iBuff11 * 2;
end
;
readln;
end
;
if sMenuSelector = 2
then
begin
clrscr;
writeln('Enter numbers to array:');
// Input
For i:= 0 to 9 do
begin
readln(aNumInput21[i]);
write(i+1);
writeln(' entered. Enter next value');
end
;
clrscr;
// Copy
For i:= 0 to 9 do
begin
aNumArr21[i]:= aNumInput21[i];
if aNumInput21[i] < 0 then aNumArr21[i]:= 0;
end
;
// Print
writeln('Displaying array a and b');
For i:= 0 to 9 do
begin
write('A');
write(i+1);
write(': ');
write(aNumInput21[i]);
write(' ');
write('B');
write(i+1);
write(': ');
write(aNumArr21[i]);
writeln('');
end
;
readln;
end
;
if sMenuSelector = 3
then
begin
clrscr;
write('Enter square matrix size:');
readln(iInputSize31);
SetLength(aMatrix31,iInputSize31,iInputSize31);
// Entering vars
// Entering matrix -> Scrolling rows
For i:= 0 to iInputSize31 - 1 do
begin
For j:= 0 to iInputSize31 - 1 do
begin
write(' ');
readln(aMatrix31[i,j]);
//write(i);
end
;
writeln('');
write('Row entered. Next row number:');
writeln(i+2)
end
;
clrscr;
// Displaying matrix + searching min/max -> Scrolling rows
iMaxBuff31:= aMatrix31[0,0];
iMinBuff31:= aMatrix31[0,0];
iMinCoord31:= 0;
iMinCoord32:= 0;
iMaxCoord31:= 0;
iMaxCoord32:= 0;
For i:= 0 to iInputSize31 - 1 do
begin
For j:= 0 to iInputSize31 - 1 do
begin
//write(' ');
write(aMatrix31[i,j]:4);
if aMatrix31[i,j] > iMaxBuff31 then
begin
iMaxBuff31:= aMatrix31[i,j];
iMaxCoord31:= i;
iMaxCoord32:= j;
end;
if aMatrix31[i,j] < iMinBuff31 then
begin
iMinBuff31:= aMatrix31[i,j];
iMinCoord31:= i;
iMinCoord32:= j;
end;
//write(i);
end
;
writeln('');
end
;
write('Max:');
writeln(iMaxBuff31);
write('Max Coords: ');
write(iMaxCoord31+1);
write(':');
writeln(iMaxCoord32+1);
write('Min:');
writeln(iMinBuff31);
write('Min Coords: ');
write(iMinCoord31+1);
write(':');
writeln(iMinCoord32+1);
readln;
end
;
if sMenuSelector = 4
then
begin
clrscr;
write('Enter size:');
readln(iInputSize41);
iInputSize41:= iInputSize41 + 1;
//Setting array
SetLength(aMainArr41,iInputSize41,iInputSize41);
//Set first var to 1
aMainArr41[0,0]:= 1;
//Calculating row! [i-1][j-1]+[i-1][j]
for i:= 1 to iInputSize41 - 1 do
begin
for j:= 0 to i do
begin
if (j - 1) >= 0 then iProc42:= aMainArr41[i-1,j-1] else iProc42:= 0;
iProc41:= aMainArr41[i-1,j];
aMainArr41[i,j]:= (iProc41 + iProc42);
end
;
end
;
For i:= 0 to iInputSize41 - 1 do
begin
For j:= 0 to iInputSize41 - 1 do
begin
if aMainArr41[i,j] > 0 then write(aMainArr41[i,j]:4);
end
;
writeln('');
end
;
readln;
clrscr;
//kinda strings used
For i:= 0 to iInputSize41 - 1 do
begin
// adding tabulator (3 spaces)
sTabulator:= ' ';
sTabulator41:= sTabulator;
For k:=0 to (iInputSize41 - 1) - i do sTabulator41:= sTabulator + sTabulator41;
write(sTabulator41);
For j:= 0 to iInputSize41 - 1 do
begin
if aMainArr41[i,j] > 0 then write(aMainArr41[i,j]:4);
write(' ');
end
;
writeln('');
end
;
readln;
end
;
end.
Документ
Категория
Рефераты
Просмотров
17
Размер файла
14 Кб
Теги
lab3
1/--страниц
Пожаловаться на содержимое документа