e se este valor existe no vetor, ele é marcado
imediatamente no próprio vetor de inteiros.
//---------------------------------------------------------------------------
//
#include <fmx.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
int n;
String str_1 = " ";
String str_2 = " ";
int a = 0, b = 0;
int A [ 100 ], i;
// ---------------------------------------------------------------------------
void __fastcall TForm1::FormShow_1(TObject *Sender, TCanvas *Canvas, const TRectF &ARect)
{
Text3->Text = "IMPRIMINDO VETOR E PESQUISANDO";
for( i = 0; i < 100; i++ ) {
A [ a ] = i;
a++;
}
for ( a = 0; a < 100; a++ ) {
str_1 += " ";
if ( A [ a ] % 10 == 0 ) {
str_1 += ( "\n" );
}
if ( A [ a ] >= 0 && A [ a ] < 10 ) {
str_1 += ( "0" );
}
str_1 += A [ a ];
}
//Declara um TText no form para imprimir
Text1->Text = str_1;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::OkClick(TObject *Sender)
{
n = Edit1 -> Text * 1;
for ( a = 0; a < 100; a++ ) {
str_2 += " ";
if ( A [ a ] % 10 == 0 ) {
str_2 += ( "\n" );
}
if ( A [ a ] == n ) {
str_2 += A [ a ];
Text2->Text = str_2;
}
}
n = 0;
str_2 = " ";
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Objects.hpp>
#include <FMX.Types.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Edit.hpp>
#include <FMX.StdCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TText *Text1;
TText *Text2;
TRectangle *Rectangle1;
TText *Text3;
TEdit *Edit1;
TButton *Button1;
void __fastcall FormShow_1(TObject *Sender, TCanvas *Canvas, const TRectF &ARect);
void __fastcall OkClick(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
object Form1: TForm1
Left = 405
Top = 192
Caption = 'IMPRIMINDO VETOR E PESQUISANDO'
ClientHeight = 300
ClientWidth = 600
Position = Designed
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
OnPaint = FormShow_1
Left = 405
Top = 192
DesignerMasterStyle = 0
object Text1: TText
Position.X = 192.000000000000000000
Position.Y = 32.000000000000000000
Size.Width = 265.000000000000000000
Size.Height = 240.000000000000000000
Size.PlatformDefault = False
TextSettings.Font.Size = 16.000000000000000000
TextSettings.HorzAlign = Leading
TextSettings.VertAlign = Leading
object Text2: TText
Size.Width = 265.000000000000000000
Size.Height = 240.000000000000000000
Size.PlatformDefault = False
TextSettings.Font.Size = 16.000000000000000000
TextSettings.FontColor = claRed
TextSettings.WordWrap = False
TextSettings.HorzAlign = Leading
TextSettings.VertAlign = Leading
end
end
object Rectangle1: TRectangle
Fill.Color = claNull
Size.Width = 600.000000000000000000
Size.Height = 300.000000000000000000
Size.PlatformDefault = False
Stroke.Color = claBlue
Stroke.Thickness = 10.000000000000000000
end
object Text3: TText
AutoSize = True
Position.X = 152.000000000000000000
Position.Y = 16.000000000000000000
Size.Width = 89.000000000000000000
Size.Height = 17.000000000000000000
Size.PlatformDefault = False
TextSettings.Font.Size = 18.000000000000000000
TextSettings.FontColor = claRed
TextSettings.WordWrap = False
end
object Edit1: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 0
FilterChar = '0123456789'
Position.X = 32.000000000000000000
Position.Y = 248.000000000000000000
Size.Width = 49.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
end
object Button1: TButton
Position.X = 88.000000000000000000
Position.Y = 248.000000000000000000
Size.Width = 33.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
Text = 'Ok'
OnClick = OkClick
end
end
Nenhum comentário:
Postar um comentário
Observação: somente um membro deste blog pode postar um comentário.