Recent

Author Topic: Compiling to code  (Read 585 times)

Sneg

  • New member
  • *
  • Posts: 5
Compiling to code
« on: November 13, 2020, 12:03:02 am »
Hi, all.
The first week I study lazarus and immediately give it is not clear what, I decided to contact you.
The task:
Find the difference R between the maximum and minimum elements of the array W:
https://imgur.com/BXwwbL7
Sorry for the picture on a third-party resource, I did not understand how to insert it on the site.

winni

  • Hero Member
  • *****
  • Posts: 2121
Re: Compiling to code
« Reply #1 on: November 13, 2020, 02:10:06 am »
Hi!

You know how to create a project and to put a button on a form?

Do it and put this code in the empty body of the procedure Button1Click

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. const matrix : Array[1..3,1..3] of integer = (
  3.                         (-1, -6, -8),
  4.                         (24, 15, 13),
  5.                         (-7, 73 ,-2)   );
  6. var x,y : integer;
  7.     min: integer = 0;
  8.     max: integer = 0;
  9. begin
  10.    for x := 1 to 3 do
  11.       begin
  12.         for y := 1 to 3 do
  13.            begin
  14.             if matrix[x,y] < min  then min := matrix[x,y];
  15.             if matrix[x,y] > max then max := matrix[x,y];
  16.            end; // y
  17.         end; //x
  18.  showMessage ('min: '+IntToStr(min)+ ' / '+'max: '+IntToStr(max) );
  19. end;

Winni

Sneg

  • New member
  • *
  • Posts: 5
Re: Compiling to code
« Reply #2 on: November 13, 2020, 11:53:19 pm »
winni, thank you very much, but could you please add some code and find the difference between the maximum number and the minimum.

winni

  • Hero Member
  • *****
  • Posts: 2121
Re: Compiling to code
« Reply #3 on: November 14, 2020, 03:30:17 am »

Code: Pascal  [Select][+][-]
  1. showMessage ('min: '+IntToStr(min)+ ' / '+'max: '+IntToStr(max)  +LineEnding+
  2. 'Difference min max: '+IntToStr(max - min)    );
  3.  
  4.  

Homework now done??

Winni

 

TinyPortal © 2005-2018