#include <stdio.h>
#include <stdlib.h>
#define max_Size 1000
int* main_Tab;
int is_First(int value)
{
int i,sum;
sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return 1;
else
return 0;
}
void init_Tab()
{
int i,j;
main_Tab=malloc(sizeof(int)*max_Size);
i=0;
j=1;
do
{
if(is_First(j))
{
main_Tab[i]=j;
++i;
}
++j;
}while(i<max_Size);
}
void destroy_Tab()
{
free(main_Tab);
}
typedef struct
{
int y1;
int y2;
int* value;
}my_Queue;
void start_Queue(my_Queue* temp_Queue)
{
temp_Queue->y1=0;
temp_Queue->y2=0;
temp_Queue->value=(int*)malloc(max_Size*sizeof(int));
}
int show_Size(my_Queue* temp_Queue)
{
int temp_Value;
temp_Value=temp_Queue->y2-temp_Queue->y1;
return temp_Value;
}
void destroy_Queue(my_Queue* temp_Queue)
{
free(temp_Queue->value);
}
void add_Queue(my_Queue* temp_Queue, int temp_Value)
{
temp_Queue->value[temp_Queue->y2]=temp_Value;
temp_Queue->y2++;
}
int write_values_Queue(my_Queue* temp_Queue)
{
int temp_Value;
temp_Value=temp_Queue->value[temp_Queue->y1];
temp_Queue->y1++;
return temp_Value;
}
int main(int argc, char **argv)
{
int i;
init_Tab();
my_Queue* test_Queue=(my_Queue*)malloc(sizeof(my_Queue));
start_Queue(test_Queue);
for(i=0;i<max_Size;i++)
{
add_Queue(test_Queue,main_Tab[i]);
}
for(i=0;i<max_Size;i++)
{
printf("%d ) %d\n",i+1,write_values_Queue(test_Queue));
}
destroy_Queue(test_Queue);
free(test_Queue);
destroy_Tab();
return 0;
}
C/C++ Algorithms and programs
wtorek, 1 września 2026
struct my_Queue - gcc
piątek, 20 marca 2026
Opening a file from Libre Office in the StringGrid component - C++ Builder
File Libre Office - STAFF.ods
sobota, 21 lutego 2026
Moon phases - C++ Builder
środa, 18 lutego 2026
Valarray - C++ Builder
private: // User declarations
float tab[5];
#include <vcl.h>
#include <valarray>
#include <stdlib.h>
#include <time.h>
#pragma hdrstop
#include "p_aarray.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
srand(time(NULL));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
StringGrid1->ColCount=5;
StringGrid1->RowCount=1;
StringGrid1->FixedCols=0;
StringGrid1->FixedRows=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
const float a=50.00;
for(i=0;i<5;i++)
{
tab[i]=(1+rand()%100)/a;
StringGrid1->Cells[i][0]=FloatToStrF(tab[i],ffGeneral,4,4);
}
std::valarray<float> bb {tab[0],tab[1], tab[2], tab[3], tab[4]};
Label1->Caption="sum() = "+FloatToStrF(bb.sum(),ffGeneral,4,4);
Label2->Caption="min() = "+FloatToStrF(bb.min(),ffGeneral,4,4);
Label3->Caption="max() = "+FloatToStrF(bb.max(),ffGeneral,4,4);
std::valarray<float> temp_Sqrt=sqrt(bb);
Label4->Caption="sqrt() = "+FloatToStrF(temp_Sqrt[0],ffGeneral,4,4)+" "+
FloatToStrF(temp_Sqrt[1],ffGeneral,4,4)+" "+
FloatToStrF(temp_Sqrt[2],ffGeneral,4,4)+" "+
FloatToStrF(temp_Sqrt[3],ffGeneral,4,4)+" "+
FloatToStrF(temp_Sqrt[4],ffGeneral,4,4)+" ";
}
sobota, 20 grudnia 2025
Fonts in Windows (C++ Builder)
private: // User declarations
UnicodeString text;
void __fastcall Begin();
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
UnicodeString d,t;
d=DateToStr(Date());
t=TimeToStr(Time());
text=d+" "+t;
Label1->Caption=text;
}
void __fastcall TForm1::Begin()
{
ListBox1->Items->Clear();
ComboBox1->Items->Clear();
ComboBox1->Items->Assign(Screen->Fonts);
ComboBox1->Text="";
ListBox1->Items->Assign(Screen->Fonts);
Label2->Caption="All fonts in Windows (testing ComboBox) ";
Label3->Caption="All fonts in Windows (testing ListBox) ";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Begin();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
Label2->Font->Name=ComboBox1->Text;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1Click(TObject *Sender)
{
Label3->Font->Name=ListBox1->Items->Strings[ListBox1->ItemIndex];
}
poniedziałek, 24 listopada 2025
Getting data from a file into a StringGrid - C++ Builder
czwartek, 16 października 2025
Discrete knapsack problem - C++ Builder




