1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Firlakuza [10]
3 years ago
15

Write a c++ program to print even numbers from 1 to 20​

Computers and Technology
1 answer:
Novay_Z [31]3 years ago
8 0

Answer:

#include <bits/stdc++.h>

using namespace std;

// Function to print even numbers

void printEvenNumbers(int N)

{

cout << "Even: ";

for (int i = 1; i <= 2 * N; i++) {

// Numbers that are divisible by 2

if (i % 2 == 0)

cout << i << " ";

}

}

// Function to print odd numbers

void printOddNumbers(int N)

{

cout << "\nOdd: ";

for (int i = 1; i <= 2 * N; i++) {

// Numbers that are not divisible by 2

if (i % 2 != 0)

cout << i << " ";

}

}

// Driver code

int main()

{

int N = 20;

printEvenNumbers(N);

printOddNumbers(N);

return 0;

}

Explanation:

Note: This will find both odd and even numbers, you have to change the number above to the number of your choice

For even numbers

Even number are numbers that are divisible by 2.

To print even numbers from 1 to N, traverse each number from 1.

Check if these numbers are divisible by 2.

If true, print that number.

For odd numbers

Odd number are numbers that are not divisible by 2.

To print Odd numbers from 1 to N, traverse each number from 1.

Check if these numbers are not divisible by 2.

If true, print that number

You might be interested in
Match the limits of the user with an appropriate design response. 1. severe arthritis, unable to type or use a mouse on a reliab
ololo11 [35]
Idk........................
4 0
3 years ago
David has created a lot of styles and now his Quick Style Gallery contains styles he no longer uses.
shusha [124]

Answer:

Right-click the style in the Quick Styles Gallery, and select the Remove from Quick Style Gallery option.

Explanation:

3 0
4 years ago
⦁ ¿Cuáles son los recursos naturales que se utilizan en tu comunidad para generar energía eléctrica?
xxTIMURxx [149]
Turbinas de viento y turbinas de agua son utilizadas, entonces la respuesta podria ser viento y agua
7 0
3 years ago
What would you use to exit from a for each activity and continue the execution of the workflow?
mr_godi [17]

Answer:

Break activity

Explanation:

The Break activity simply allows a user to stop the loop at any point chosen, and then continue with another activity or the next activity.

4 0
3 years ago
What is computer hardware / software​
Pavel [41]

Answer: <u>Computer hardware is any physical device used in or with your machine, like for example, a mouse, or a keyboard.</u> Computer software is a collection of programming code installed on your computer's hard drive it can process billions of data and inputs through this.

Hope this helps!

5 0
3 years ago
Other questions:
  • Ascending and descending are examples of
    5·2 answers
  • Operating systems such as Microsoft Windows use a specific character before a file extension to separate it from the filename. W
    9·2 answers
  • Create an array of strings. Let the user decide how big this array is, but it must have at least 1 element. Prompt them until th
    8·1 answer
  • Help pls<br><br> What type of link is used to call this file?
    5·2 answers
  • Which careers have the highest minimum experience requirement?
    14·1 answer
  • Help me? ill do anything ill let u smash me or anything just HELP!
    15·2 answers
  • I don’t understand this, i need help
    7·1 answer
  • How is a technical certificate like a computer-related associate degree?
    11·1 answer
  • A(n) ____ is a live internet presentation that supports interactive communications between the presenter and the audience.
    13·1 answer
  • HELP ME PLEASE 41 PTS
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!