poniedziałek, 21 grudnia 2020
StringGrid and fstream (C++ Builder)
niedziela, 13 grudnia 2020
pthread_create gcc
#include <stdio.h>
#include <pthread.h>
int even_Numbers(int value)
{
if(value%2==0)
return 1;
else
return 0;
}
int odd_Numbers(int value)
{
if(value%2!=0)
return 1;
else
return 0;
}
void write_Even(void* sd)
{
int l=1;
while(1)
{
if(even_Numbers(l))
fprintf(stderr,"%d\n",l);
++l;
}
return NULL;
}
void write_Odd(void* sd)
{
int l=1;
while(1)
{
if(odd_Numbers(l))
fprintf(stderr,"%d\n",l);
++l;
}
return NULL;
}
pthread_t new_Thread;
int main()
{
pthread_create(&new_Thread,NULL,&write_Odd,NULL);
while(1)
write_Even(stderr);
return 0;
}
czwartek, 3 grudnia 2020
Right triangles with prime numbers (C++)
#include <iostream>
#define gg 1000
using namespace std;
struct m_Point
{
int x;
int y;
int z;
};
int *TAB1,*TAB2;
bool is_Traingle(int a, int b, int c)
{
bool value=false;
if((a*a)+(b*b)==(c*c))
value=true;
if((a*a)+(c*c)==(b*b))
value=true;
if((b*b)+(c*c)==(a*a))
value=true;
return value;
}
bool is_First(int value)
{
int i,sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
void init_Tab()
{
int i,j;
TAB1=new int[gg];
TAB2=new int[gg];
i=0;
j=2;
do
{
if(is_First(j))
{
TAB1[i]=j;
++i;
}
++j;
}while(i<gg);
i=0;
j=1;
do
{
if(!is_First(j))
{
TAB2[i]=j;
++i;
}
++j;
}while(i<gg);
}
void delete_Tab()
{
delete TAB2;
delete TAB1;
}
int main(int argc, char **argv)
{
int i,j,k,l=0;
init_Tab();
struct m_Point *TR=new struct m_Point[gg];
for(i=0;i<gg;i++)
{
TR[i].x=0;
TR[i].y=0;
TR[i].z=0;
}
for(i=0;i<gg;i++)
{
for(j=0;j<gg;j++)
{
for(k=0;k<gg;k++)
{
if(is_Traingle(TAB1[i],TAB2[j],TAB2[k]))
{
TR[l].x=TAB1[i];TR[l].y=TAB2[j];TR[l].z=TAB2[k];
++l;
}
if(is_Traingle(TAB1[i],TAB1[i],TAB2[k]))
{
TR[l].x=TAB1[i];TR[l].y=TAB2[j];TR[l].z=TAB2[k];
++l;
}
if(is_Traingle(TAB1[i],TAB1[i],TAB1[k]))
{
TR[l].x=TAB1[i];TR[l].y=TAB2[j];TR[l].z=TAB2[k];
++l;
}
}
}
}
for(i=0;i<l;i++)
{
cout<<i+1<<") "<<TR[i].x<<" - "<<TR[i].y<<" - "<<TR[i].z<<endl;
}
delete [] TR;
delete_Tab();
return 0;
}
YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL