Ask Question
8 July, 11:53

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

+5
Answers (1)
  1. 8 July, 15:50
    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?
Get an answer to your question ✅ “How would you print just the even numbers from 2 to 1000 ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers