Skip to content

Instantly share code, notes, and snippets.

@harkalygergo
Last active December 9, 2015 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harkalygergo/3593cd46fb05ae60a4e2 to your computer and use it in GitHub Desktop.
Save harkalygergo/3593cd46fb05ae60a4e2 to your computer and use it in GitHub Desktop.
euler 20151125
/*
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>
/*
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ék: %.20Lf\n", sum);
}
printf("sum1 végértéke: %.20Lf\n", sum+1);
}
void* lim()
{
for(i=1; i<=20; i++, n++)
{
sum2 = pow(1 + 1.0/n, n);
//printf("sum2 aktuális érték: %.20Lf\n", sum2);
}
printf("sum2 végértéke: %.20Lf\n", sum2);
}
/* MAIN */
void main(int argc, char** argv[])
{
parameter* par= (parameter*)malloc(sizeof(parameter)*argc);
pthread_t thread1, thread2;
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