Tuesday, October 16, 2018

Arrays in Pascal

Single dimension array in Pascal

var
   x:array[1..10] of integer;     {define single dimention array}
   i:integer;
begin
  {repetition to enter numbers into array}
  for i:=1 to 10 do
  begin
    write('Enter a Number ?');
    readln(x[i]);
  end;
  {repetition to print all array elements}
  for i:=1 to 10 do
  begin
    write(i);
    write('number is :');
    writeln(x[i]);
  end;
  readln;
end.

List is used as array in Python, If we write the above program in Python

#list in Python
mylist=[] # define list
# enter element into Python
for i in range(0,10):
    num=int(input("Enter a number ?"))
    mylist.append(num)
# print elments of list
print(mylist)


No comments:

Post a Comment