Ask Question
18 August, 13:17

How would you print just the even numbers from 2 to 1000

+2
Answers (1)
  1. 18 August, 14:34
    0
    Here is code in C+ + to print all the even numbers from 2 to 1000.

    #include

    using namespace std;

    //main function

    int main () {

    / / loop which iterate from 2 to 1000 and print all the even numbers

    cout<<"All the even numbers from 2 to 1000 are:"<
    for (int i=2; i<=1000; i++)

    {

    / / checking for even number

    if (i%2==0)

    {

    / / print the even number

    cout<
    }

    }

    return 0;

    }

    Explanation:

    First we declare a variable "i" of integer type to iterate a for loop from 2 to 1000 (both inclusive). In the for loop it will check for every number, if remainder is equal to zero when it divided by 2 then number is even and That number will be printed. If the number is not even then it will check for the next number. When the it checks for i=1000, it will come out from the loop.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “How would you print just the even numbers from 2 to 1000 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers