寻找最小的正数为奇数位置 [英] Find smallest positive number that is a odd number position

查看:244
本文介绍了寻找最小的正数为奇数位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有序列号生成程序,我需要它来搜索最小的正数为帕斯卡一个奇数位置。

I have array number generator program and I need it to search smallest positive number that is a odd number position in Pascal.

下面是我的程序:

Program UZD5_linx;
uses crt, Math;
var MasGen:array [1..20] of real;
    i,id:integer;
    x,sk,MinVP:real;
    MAKE:text;
    funk:string;
    label SAKUMS,DZOB,REZ,BEIGAS;
begin
  assign(MAKE, 'Gnerejums.txt');
  rewrite(MAKE);
  clrscr;
  randomize;
SAKUMS:
    writeln('Darbibas');
    writeln('Ievadisana - Darbs');
    writeln('Uzdevumu beigsana - Beigas');
    writeln('Parbaude - Test');
    read(funk);
    if funk='Darbs' then goto DZOB; //main generetor
    if funk='Beigas' then goto BEIGAS;//end
    if funk='Test' then goto REZ;//The main algorithm
    readln;
DZOB:
  writeln('Ievadiet savu mainigo sin vertibu');//Read in the value
  readln(x);
  {skaitlu generacija}
  for i:=1 to 20 do
  MasGen[i]:=cos(random(20))+(random(10))*sin(x)-tan(random(30))-random(25)-cot(x);
  for i:=1 to 20 do
  begin
  writeln('Nr= ',i,' ','Vertiba=',MasGen[i]:2:3);
  writeln(MAKE,'Nr= ',i,' ','Vertiba=',MasGen[i]:2:3);
  end;
  readln;
  writeln(MAKE);
  goto SAKUMS;
REZ:
    //Algorimhm here
    goto SAKUMS; //Sakums = Start
BEIGAS:
  close (MAKE);
end.

我需要我的生成数组后,测试和写出来的最小数目是正 SK [I] ,然后写出它的地位在其阵列我是一个奇数位置(如 1,3,5,7,9,11,13,15,17,18 )。并告诉其中一个包含最小正可能值。但是,如果它没有得到任何然后打印,它现在没有这个号码。

I need that after my generated array to test and write out the smallest number that is positive sk[i] and then write out its position in its array I that is a odd number position (like 1,3,5,7,9,11,13,15,17,18). And tell which one contains the smallest positive possible value. But if it hasn't got any then print that it has none of this number.

我希望你真的明白我需要这个算法做。英语不是我的母语。感谢您的帮助。

I hope you really understand what I need this algorithm to do. English isn't my native language. Thanks for the help.

推荐答案

一个重复,直到循环开始,I = 1,并增加2对每个周期都会让你的目标奇指标。

A repeat until loop starting with i = 1 and adding 2 for every cycle will let you target the odd indexes.

一个MINIX变量控制了积极的最小值是否被发现,它有它的索引。

A minIx variable controls whether a positive min value is found and which index it has.

i := 1;
minIx := 0;
minVal := 0;
repeat
  if (arr[i] > 0) then begin // Positive value
    if (minIx = 0) or (arr[i] < minVal) then begin
      minVal := arr[i];
      minIx := i;
    end; 
  end;
  i:= i+2;
until i > 19;
if (minIx > 0) then 
  WriteLn('Min:',minVal,' Ix:',minIx)
else
  WriteLn('No positive values in odd index positions.');

这篇关于寻找最小的正数为奇数位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆