Solved Pascal. Array, find smallest positive value.

Custom / CUSTOM
October 30, 2011 at 07:57:09
Specs: Windows 7, i7 2600 @ 3.4GhZ / 8 GB
I've to do this homework for Uni, yet I can't find where have I made the mistake, I'm in a rush as well, so hopefully someone can help me asap. I do apologize that it's in my first language, but idea should be obvious as to how things work. Only part I've to change myself is right after "Read(j)". I've to insert a fragment of code there that will find and display smallest positive value and it's index.
Here's code itself:

{ Laboratijas darbs #5 }

{ Macibu programma - aprekini viendimensiju masivaa }
{ Ciklu operatoru un masivu pielietojumu piemers}
{ Masiva elementu vertibu generacija protokola sagatavei}
program massiv1;

const num=20; {masiva izmers}
DATA : text;
oper, { izpildama programmas operacija }
{ oper=3333 beigt }
i,j : integer; {darba imdeksi }
ms: array[1..num] of real;{Masivs, kuru apstrada}
x, dx :real;
idet : integer; { indeksi rezultatam }
Maxv: real; { rezultats }
assign (DATA, 'Data.txt');
x:=0.27; dx:=0.345;

writeln( 'Programma domata ciklu operatoru un masivu apgusanai ');
writeln( ' 3333 - beigt');
writeln( ' 1111 - genereet masivu ar standarta sakumvertibam ');
writeln( ' jebkurs cits skaitlis genereet masivu ar pasa uzdotam sakumvertibam');
read( oper);
if oper=3333 then goto BEIGAS;
if oper=1111 then goto SOLVE;
{masiva aizpildisana un aprekini }
writeln( 'ievadi divus realus skaitlus,tie noteiks masiva elem. vertibas');
read(x, dx);

writeln(DATA); writeln(DATA); writeln(DATA); writeln(DATA);
writeln(DATA, 'Masivs ieguts ar sekojosam x un dx vertibam');
writeln(DATA,' x=', x:6:4,' dx=',dx:6:4);
for i:=1 to num do
end; writeln;
for i:=1 to num do {Uzgenereta masiva izvads}
write( ' "',i:2, '"', ms[i]:10:5)
for i:=1 to num do {Uzgenereta masiva izvads failaa}
write(DATA, ' "',i:2, '"', ms[i]:9:5);
if (i mod 4=0) then writeln(DATA);
writeln; writeln(' Lai turpinatu ievadi jebkuru skaitli ');
MaxV:=ms[1]; idet:=1;
for i:=1 to num do
if ((ms[i] < Maxv) and (ms[i] > 0)) then
MaxV:= ms[i];

Writeln(' Mazaakaa pozitiiva elementa veertiiba ir :', MaxV:10:5);
Writeln(' Mazaakaa pozitiivaa elementa indeks ir :', idet:5);

goto MENU;
close (DATA);

See More: Pascal. Array, find smallest positive value.

Report •

October 30, 2011 at 10:10:41
✔ Best Answer
Hello Karlis,

I admit I don't fully understand your code due to Latvian language and other minor formal things. Stated the use of labels is horrible in Pascal, are you sure MaxV:=ms[1] leads to a positive value? Otherwise ms[..] will never be assigned as result. Better you code MaxV:=20 since 10 * sin(x) is never greater than 10.

P.S.: I will send you what I promised.

Report •

October 30, 2011 at 10:44:54
There was some kind of example, so I kind of followed that, but Your version works and that's what matters. I've to finish my HW so then I can get deeper in this all.

P.s I'd have sent You an email regarding this, but I'm sort of in hurry and wasn't sure what time is it or if You're busy and all.

Thanks as always Ivo!

Report •
Related Solutions

Ask Question