Unknown model· unknown
from NVIDIA HelpSteer3 Preference
Write a complete C++ implementation for FizzBuzz.
- User
Write a complete C++ implementation for FizzBuzz.
- Assistant
Sure, here is a simple implementation of FizzBuzz in C++:
code#include <iostream> int main() { for (int i = 1; i <= 100; i++) { if (i % 3 == 0 && i % 5 == 0) { std::cout << "FizzBuzz" << std::endl; } else if (i % 3 == 0) { std::cout << "Fizz" << std::endl; } else if (i % 5 == 0) { std::cout << "FizzBuzz" << std::endl; } else { std::cout << i << std::endl; } } return 0; }This program uses a
forloop to iterate from 1 to 100, and for each number it checks whether it is divisible by 3, 5, or both. If the number is divisible by both 3 and 5, it prints "FizzBuzz". If it is only divisible by 3, it prints "Fizz", and if it is only divisible by 5, it prints "Buzz". If the number is not divisible by either 3 or 5, it simply prints the number.I hope this helps! Let me know if you have any questions.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.