Generation

generate functionFri, 06 Dec 2024

Develop a pseudocode that allows you to print the even numbers between 1 and 50

Here's a simple pseudocode to print even numbers between 1 and 50 in C++: ``` FUNCTION printEvenNumbers(): START FOR i FROM 1 TO 50 IF i IS EVEN PRINT i END FOR END CALL printEvenNumbers() ``` However, in C++, we can use a more efficient and idiomatic way to achieve this using a for loop with a step of 2: ```cpp #include <iostream> int main() { for (int i = 2; i <= 50; i += 2) { std::cout << i << std::endl; } return 0; } ``` This code will print all even numbers between 2 and 50 (inclusive). If you want to start from 1, you can simply change the initial value of `i` to 2.

Questions about programming?Chat with your personal AI assistant