Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 25.12.2015, 20:14   #1
Bleddix
 
Регистрация: 25.12.2015
Сообщений: 7
По умолчанию Произведение найбольшего положительного и найменшего отрицательного числа

Произведение наибольшего положительного и наименьшего отрицательного числа
Помогите с кодом ребят



Для ввода элементов использовать StringGrid

Последний раз редактировалось Bleddix; 25.12.2015 в 20:18.
Bleddix вне форума Ответить с цитированием
Старый 25.12.2015, 20:41   #2
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

Код:
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
			Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids;

type

			{ TForm1 }

   TForm1 = class(TForm)
						StringGrid1: TStringGrid;
						procedure FormCreate(Sender: TObject);
      procedure StringGrid1SetEditText(Sender: TObject; ACol,
									ARow: Integer; const Value: string);
			private
						{ private declarations }
			public
						{ public declarations }
			end;

var  max,min:Double;
			Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
			const Value: string);
var d:double;
begin
 if TryStrToFloat(StringReplace(Value,',','.',[]),d) then begin
  if (d>0)and(d>max) or (Tag=0) then max:=d;
  if (d<0)and(d<min) or (Tag=0) then min:=d;
  Tag:=1;
 end;
 Caption:=Format('Max=%5.2f * Min=%5.2f = %5.2f',[max,min,max*min]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Tag:=0;
  StringGrid1.Options:=StringGrid1.Options+[goEditing,goAlwaysShowEditor];
  FormatSettings.DecimalSeparator:='.';
end;

end.
Подходит идея?
I'm learning to live...
Stilet вне форума Ответить с цитированием
Старый 25.12.2015, 20:56   #3
Bleddix
 
Регистрация: 25.12.2015
Сообщений: 7
По умолчанию

Цитата:
Сообщение от Stilet Посмотреть сообщение
Код:
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
			Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids;

type

			{ TForm1 }

   TForm1 = class(TForm)
						StringGrid1: TStringGrid;
						procedure FormCreate(Sender: TObject);
      procedure StringGrid1SetEditText(Sender: TObject; ACol,
									ARow: Integer; const Value: string);
			private
						{ private declarations }
			public
						{ public declarations }
			end;

var  max,min:Double;
			Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
			const Value: string);
var d:double;
begin
 if TryStrToFloat(StringReplace(Value,',','.',[]),d) then begin
  if (d>0)and(d>max) or (Tag=0) then max:=d;
  if (d<0)and(d<min) or (Tag=0) then min:=d;
  Tag:=1;
 end;
 Caption:=Format('Max=%5.2f * Min=%5.2f = %5.2f',[max,min,max*min]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Tag:=0;
  StringGrid1.Options:=StringGrid1.Options+[goEditing,goAlwaysShowEditor];
  FormatSettings.DecimalSeparator:='.';
end;

end.
Подходит идея?
Мне нужно чтоб таблица кнопкой заполнялась, и выводила результат над ней
Если не сложно можете это сделать?

Последний раз редактировалось Bleddix; 25.12.2015 в 21:00.
Bleddix вне форума Ответить с цитированием
Старый 25.12.2015, 21:44   #4
Bleddix
 
Регистрация: 25.12.2015
Сообщений: 7
По умолчанию

Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  i,j,s:integer;
  a:array[1..10,1..10] of integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin   randomize;
 s:=0;
    for i:=1 to 10 do
      for j:=1 to 10 do   begin
        a[i,j]:=random(100)-50;
        StringGrid1.Cells[i,j] := IntToStr(a[i,j]);
          end;
    for i:= 1 to 10 do
for j:= 1 to 10 do
if a[i,j] > s then    begin
s:= (a[i,j]);

Label2.Caption:='наибольший положительный элемент ' + inttostr(s)+ ' координаты ' + inttostr(i)+ ' ; '+inttostr(j);


end;

end.

Что-то типа этого, только вместо наибольшего положительного элемента подставить произведение наибольшего положительного и наименьшего отрицательного чисел.

Последний раз редактировалось Stilet; 26.12.2015 в 09:56.
Bleddix вне форума Ответить с цитированием
Старый 26.12.2015, 09:58   #5
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

Код:
procedure TForm1.Button1Click(Sender: TObject);

begin   randomize;
 s:=0;
    for i:=1 to 10 do
      for j:=1 to 10 do   begin
        a[i,j]:=random(100)-50;
        StringGrid1.Cells[i,j] := IntToStr(a[i,j]);
          end;
    for i:= 1 to 10 do for j:= 1 to 10 do
      if (a[i,j] > s) and (a[i,j]>0) then  s:= (a[i,j]) else
       if (a[i,j] < s2) and (a[i,j]<0) then  s2:= (a[i,j]) ;

Label2.Caption:='наибольший положительный элемент ' + inttostr(s)
 +'наименьший отрицательный элемент ' + inttostr(s2);


end;
I'm learning to live...
Stilet вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Нахождение наибольшего отрицательного и наименьшего положительного числа. Paradoх Общие вопросы C/C++ 3 09.12.2012 16:10
Корень из отрицательного числа Baizer Помощь студентам 1 12.12.2011 14:34
Вычислить корень 5 степени из положительного числа Dartchuwak Общие вопросы C/C++ 4 12.12.2009 22:08
Кубический корень от отрицательного числа Vito89 Помощь студентам 9 29.09.2009 14:40
формат отрицательного числа zetrix Microsoft Office Excel 0 30.10.2006 18:54