Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

even and odd numbers 1 to 100

#include <iostream>
using namespace std;
int main()
{
    string even = "";
    string odd = "";

    for (int i = 0; i <= 100; i++)
    {

        if (i % 2 == 0)
        {
            even.append(to_string(i) + ", ");
        }
        else
        {
            odd.append(to_string(i) + ", ");
        }
    }

    cout << "these numbers are even  
"
         << even << endl;
    cout << "these numbers are odd  
"
         << odd << endl;
}
 
PREVIOUS NEXT
Tagged: #odd #numbers
ADD COMMENT
Topic
Name
5+8 =