gpt-4-0314· OpenAI
Arena Human Preference 55K
Write a C++ program to print the first 10,000 prime numbers.
- User
Write a C++ program to print the first 10,000 prime numbers.
- Assistant
Here's a C++ program that prints the first 10,000 prime numbers:
#include <iostream> #include <cmath> bool isPrime(int number) { if (number <= 1) { return false; } for (int i = 2; i <= std::sqrt(number); i++) { if (number % i == 0) { return false; } } return true; } int main() { int primeCount = 0; int number = 2; while (primeCount < 10000) { if (isPrime(number)) { std::cout << number << std::endl; primeCount++; } number++; } return 0; }To compile and run this program, save it to a file named
primes.cpp, then open a terminal or command prompt and navigate to the directory containing the file. Run the following commands:g++ -o primes primes.cpp ./primesOn Windows, replace
./primeswithprimes.exe.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.