data
data

Reputation: 39

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();
    }
    else
    {
        System.out.print("^_^ Input The Next Value:");
        A[m]= scan.nextInt();
    }
}

thank you

Upvotes: 0

Views: 951

Answers (4)

John
John

Reputation: 55

read(a[m]);

should work perfectly.

Upvotes: 1

Ken Pemberton
Ken Pemberton

Reputation: 21

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.

Upvotes: 0

Glaydson
Glaydson

Reputation: 1

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...

Upvotes: -1

royas
royas

Reputation: 4936

Try: readln(a[m]);

Upvotes: 3

Related Questions