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
This rlly isnt a question but give me some movies to watch or netflix movies/shows to watch
katovenus [111]
White chicks is a good one
5 0
3 years ago
Read 2 more answers
A _____ miniature battery operated transmitter that can be propelled through a non-metallic pipe or purpose of locating
Anna11 [10]
I think it is the model ET-2. Not quite sure.
7 0
3 years ago
Ron wants to install an energy efficient and long lasting device for lighting in his new home. Which device should he use?
olga2289 [7]
Ron will most likely want to buy tube lights since that is a good energy saver.
4 0
3 years ago
Read 2 more answers
Which of the following tools is specifically designed to test the dc voltage on a hard disk drive
Leya [2.2K]

Answer:

A power supply tester is specifically designed to test DC voltage on most connectors coming from a PC power supply. A multimeter measures electrical properties such as voltage, amps, and resistance.

7 0
3 years ago
Samm1E49 ok my username is mosarider489 also if others want to join u can friend me
mixer [17]

Answer:

ok

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • The arrow next to All Programs indicates _____. that this item cannot be selected that this was the most recently used item the
    7·2 answers
  • Hydropower uses moving water to do work, such as grinding grains in a mill. True False
    7·1 answer
  • Tom wants a way to automatically create ads and simplify campaign management, using his resources and Google's machine learning
    12·1 answer
  • Jim has to send an email to his boss requesting medical leave. in which field will Jim type the purpose of his email?​
    8·2 answers
  • With which type of social engineering attack are users asked to respond to an email or are directed to a website where they are
    9·1 answer
  • Question # 6
    13·1 answer
  • Consider the following method, which is intended to return the index of the first negative integer in a given array of integers.
    14·1 answer
  • Logan has developed an excellent presentation with interesting content. He received great feedback on the evaluation
    10·1 answer
  • PLEASE HELP! :)
    14·1 answer
  • How does a Cloud-first strategy differ from other approaches to Cloud?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!