Max von Zahlen ausgeben
-
Hallo Leute.Hab folgendes Problem: Ich will von 5 Zahlen die größte Zahl ermitteln.Leider ist dies nicht möglich, da ich den Fehler in meinem Quelltext nicht finde - es wird immer Null ausgegeben
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Max.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int i,a[6],m; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { for (i=1;i<=5 ;i++ ) { StringGrid1->Cells[0][i]=IntToStr(i); } { StringGrid1->Cells[1][0]="Zahlen" ; } for (i=1;i<=5 ;i++ ) { StringGrid2->Cells[0][i]=IntToStr(i); } { StringGrid2->Cells[1][0]="Ergebnis" ; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { for (i=1;i<=5;i++ ) {a[i]=StrToInt(StringGrid1->Cells[1][i]);} a[1]=m; for (i=2;i<=5 ;i++ ); { if (m<a[i]) {m=a[i];} } StringGrid2->Cells[1][1]=IntToStr(m); }Edit:
Bitte die Code-Tags verwenden. Danke!
-
Hallo,
Der Code ist ja ganz schön durcheinander.
Das größte Problem ist aber wohl das hiera[1]=m;sollte wohl eher so aussehen
m = a[1];