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
A telephone repair technician uses a meter to measure voltage on a phone line. This meter is an example of _____.
frozen [14]
It is an example of hardware.
3 0
3 years ago
Read 2 more answers
642<br> +277<br> What does 642+277
svet-max [94.6K]
Answer:
642+277= 919
6 0
3 years ago
Anyone can give me the definition of specification ?
Damm [24]
- - To state a true meaning. To be true and to be precise. 
3 0
3 years ago
Read 2 more answers
How do you add a picture to your questions? (on computer)
Fittoniya [83]

there will be a small picture of a paper clip under your question you click that and you will be able do transfer pictures that you have downloaded. hope this helps!


3 0
4 years ago
Computers were originally invented to
Afina-wow [57]

Answer:

B

Explanation:

It's B because why would it me made to play video games

5 0
3 years ago
Read 2 more answers
Other questions:
  • A file to which information is written is referred to as a(n) ____ file.
    8·1 answer
  • Signs that a listener is paying attention include:
    10·2 answers
  • Where do you access the status report of an assigned task that is open?
    12·2 answers
  • What is the most likely result of making a plan for life after high school
    14·1 answer
  • How do you get the value of an element in an array? And how about for an ArrayList?
    14·1 answer
  • Trevor owns a manufacturing business that makes specialized hiking and rock climbing gear. He is a very small player in the mark
    8·1 answer
  • Of the measures of feasibility in the accompanying figure, ____ considers points such as "Does the proposed platform have suffic
    8·1 answer
  • In most cases, it is possible to prevent an exception from terminating a program by using the try and except statements. Select
    13·1 answer
  • State 2 advantages of laptops over desktop computers
    11·2 answers
  • You need a(n) _____ to play an mp3 audio file on a desktop or laptop computer
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!