开发者

Array syntax in pascal

I am java programmer ,but now i starting to learn more abut pascal programming could you help please How to write this java syntax in pascal

        A[m] = scan.nextInt();

program is that asking the user to input the "size" then input the element... (using Array) I have done this :

writeln('How many Number you would like to sort:');
  readln(size);


  For m := 1 to size do
Begin
   if m=1 then 
 begin 
 writeln('');
 writeln('Input the first value: ');
     (????)



 End;

I didn't know how to complete it ?

java syntax is:

for( m = 0; m<size; m++)
{
    if(m == 0)
    {   
        System.out.println("");
        System.out.print("^_^ Input The First Value:");
        A[m] = scan.nextInt();
    }
    else if(m == size -1)
    {
        System.out.print("^_^ Input The Last Value:");
        A[m] = scan.nextInt();
    }
    els开发者_如何学Ce
    {
        System.out.print("^_^ Input The Next Value:");
        A[m]= scan.nextInt();
    }
}

thank you


Try: readln(a[m]);


read(a[m]);

should work perfectly.


Typing blind here, but hopefully the concept comes across:

{ in declarations }
var A: array[1..99] of integer;   { or however many you need; data workspace }
    m: integer;   { loop index }
    size: integer;


{ in code }
fillchar(A,sizeof(A),#0);  { just good practice to clear out the workspace before starting}
writeln('How many Number you would like to sort:');
readln(size);

For m := 1 to size do
  begin
    if (m=1) then 
      writeln('Input the first value: ')
    else
      if (m=size) then
        writeln('Input the last value: ')
      else
        writeln('Input the next value: ');
    readln(a[m]);
  end;

Note that I've used a 1-indexed array rather than a zero-indexed one. No reason other than I prefer it that way, saves using "-1" all over the place.


This is an attempt to use an array to receive the data. The array ps have its size limited by a variable.

var / type
A = array [1..13] : integer;
m : integer;

repeat
    readln (A[m]);
    m:=m+1;
until (m<=10);

I think...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜