GamerSK

generacia

Oct 19th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. int n,
  12.     c[255],
  13.     i,
  14.     pom;
  15. //---------------------------------------------------------------------------
  16. __fastcall TForm1::TForm1(TComponent* Owner)
  17.     : TForm(Owner)
  18. {
  19. }
  20. //---------------------------------------------------------------------------
  21. void __fastcall TForm1::btnZadanieClick(TObject *Sender)
  22. {
  23.     n = StrToInt(InputBox("Kolko cisiel chcete zadat?","Cislo","0"));
  24.     lblZadane->Caption="";
  25.     for (i = 0; i < n; i++) {
  26.         c[i] = StrToInt(InputBox("Zadajte "+IntToStr(i+1)+". cislo","Cislo","0"));
  27.         if ( i == n ) {
  28.             lblZadane->Caption=lblZadane->Caption+StrToInt(c[i]);
  29.         } else {
  30.             lblZadane->Caption=lblZadane->Caption+StrToInt(c[i])+" ";
  31.         }
  32.     }
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TForm1::btnZoradenieClick(TObject *Sender)
  36. {
  37.     i = 0;
  38.     lblZoradene->Caption = "";
  39.     while ( i!=n ) {
  40.         if ( c[i] > c[i+1] ) {
  41.             pom = c[i];
  42.             c[i] = c[i+1];
  43.             c[i+1] = pom;
  44.             i = 0;
  45.         } else i++;
  46.     }
  47.     for (i = 1; i <= n; i++) {
  48.         if ( i == n ) {
  49.             lblZoradene->Caption=lblZoradene->Caption+StrToInt(c[i]);
  50.         } else {
  51.             lblZoradene->Caption=lblZoradene->Caption+StrToInt(c[i])+" ";
  52.         }
  53.     }
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TForm1::btnGenClick(TObject *Sender)
  57. {
  58.     int s[10];
  59.     Label1->Caption="";
  60.     Label2->Caption="";
  61.     for (i = 0; i < 10; i++) {
  62.         s[i] = random(100)+1;
  63.         Label2->Caption=Label2->Caption+IntToStr(s[i])+" ";
  64.     }
  65.     i = 0;
  66.     while (i<10) {
  67.         if ( s[i] > s[i+1] ) {
  68.             pom = s[i];
  69.             s[i] = s[i+1];
  70.             s[i+1] = pom;
  71.             i=0;
  72.         } else i++;
  73.     }
  74.     for (i = 0; i < 10; i++) {
  75.         Label1->Caption=Label1->Caption+IntToStr(s[i])+" ";
  76.     }
  77.  
  78. }
  79. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment