Skip to content

Instantly share code, notes, and snippets.

@harkalygergo
Created December 9, 2015 08:45
Show Gist options
  • Save harkalygergo/0bc4d9defa5fed747299 to your computer and use it in GitHub Desktop.
Save harkalygergo/0bc4d9defa5fed747299 to your computer and use it in GitHub Desktop.
euler saját
/*
Function:
Version: 2015.12.09.
Copyright: Harkály Gergő & Lehoczky Tamás | Miskolci Egyetem
Install:
Run: cmake .; make clean; make; ./e-szam-verseny;
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <error.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include <math.h>
#define NUM_THREADS 2
/*
const char * euler()
{
int N = DIGITS+9, a[DIGITS+9], x = 0;
int n;
a[0] = 0;
a[1] = 2;
char r[DIGITS];
strcpy(r, "");
for (n = 2; n < N; ++n)
{
a[n] = 1;
}
for ( ; N > 9; --N)
{
for (n = N - 1; n > 0; --n)
{
a[n] = x % n;
x = 10 * a[n-1] + x/n;
}
strcat(r, x);
printf("%s", r);
}
return r;
}
*/
typedef struct parameter
{
char* sztring;
int id;
} parameter;
// global variables
long double E20 = 2.71828182845904523536;
long double E29 = 2.71828182845904523536028747135;
int i = 1;
float n = 1.0;
long double sum1 = 0.0, sum2 = 0.0;
/* FUNCTIONS */
void* szum()
{
unsigned long long int also = 1;
long double sum=0;
for(i=1; i<=20; i++, n++)
{
also = also*n;
sum = sum + 1.0/also;
printf("sum1 aktuális értéke %d. lépésben: %.20Lf\n", i, sum);
}
sum1 = sum+1;
//printf("sum1 végértéke: %.20Lf\n", sum+1);
pthread_exit(NULL);
}
void* lim()
{
for(i=1; i<=20; i++, n++)
{
sum2 = pow(1 + 1.0/n, n);
printf("sum2 aktuális értéke %d. lépésben: %.20Lf\n", i, sum2);
}
//printf("sum2 végértéke: %.20Lf\n", sum2);
pthread_exit(NULL);
}
/* MAIN */
void main(int argc, char** argv[])
{
/*
parameter* par= (parameter*)malloc(sizeof(parameter)*argc);
pthread_t thread1, thread2;
*/
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t<NUM_THREADS; t++)
{
if(t==0)
{
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, lim, (void *)t);
if(rc)
{
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
else
{
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, szum, (void *)t);
if(rc)
{
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
}
for(i=0; i<=1; i++)
{
if(i == 0)
{
pthread_join(threads[i], NULL);
printf("sum1 végértéke: %.20Lf\n", sum1);
}
if(i == 1)
{
pthread_join(threads[i], NULL);
printf("sum2 végértéke: %.20Lf\n", sum2);
}
}
pthread_exit(NULL);
free(threads);
/*
pthread_create(&thread1, NULL, szum, (void *) par);
pthread_create(&thread2, NULL, lim, (void *) par);
// pthread_join(thread1, NULL);
// pthread_join(thread2, NULL);
free(par);
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment