gpt-3.5-turbo-1106· OpenAI
Arena Human Preference 55K
Write C code that compute the value of Pi using the montecarlo method
- User
Write C code that compute the value of Pi using the montecarlo method
- Assistant
Here's an example of C code that computes the value of Pi using the Monte Carlo method:
c#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> int main() { int i, count = 0, num_points = 1000000; double x, y, pi_estimate; srand(time(NULL)); for (i = 0; i < num_points; i++) { x = (double)rand() / RAND_MAX; y = (double)rand() / RAND_MAX; if (x * x + y * y <= 1) { count++; } } pi_estimate = 4 * (double)count / num_points; printf("Estimated value of Pi: %lf\n", pi_estimate); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.