20/01/13 17:14
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <math.h> #include <windows.h> bool timeout = false; int t_max = 0; bool timeout = false; int t_max = 0; void *thread_check_time(void *arg) { timeout = false; printf("Inserisci il tempo massimo di attesa(espresso in secondi): "); scanf("%d", &t_max); Sleep(t_max); timeout = true; } int main(void) { float pi_greco = 0, pi_grecotot = 0, num_disp = 1.0f, error = 5, accuracy = 0; int i = 0, denominatore = 1; printf("Inserisci il grado di accuratezza : "); scanf("%f", &accuracy); pthread_t thread_time; pthread_create(&thread_time, NULL, thread_check_time, NULL); while ((error > accuracy) || (!timeout)) { pi_greco = 1.0f / num_disp; if (((i % 2) == 0) || (i == 0)) pi_grecotot = pi_grecotot + pi_greco; else pi_grecotot = pi_grecotot - pi_greco; num_disp = num_disp + 2.0f; i++; error = 4 * pi_grecotot - M_PI; } pthread_join(thread_time, NULL); printf("Il valore di pigreco approssimato a %f è %f\n", accuracy, 4 * pi_grecotot); return 0; }
Secondo me dovrebbe essere così, logicamente mi sembra corretto, eppure c' è qualcosa che non mi torna.