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
How does theatre compare with movies or television? What makes it similar to movies and television? What makes it different?
givi [52]

Answer:

you cant mess up in theatre but you can redo scences in movies, thay both have acting in them

Explanation:

im a theatre person

3 0
4 years ago
what are some of the challenges that could arise from setting up a file management system on a computer
seropon [69]
A virus maybe or ransomware
7 0
3 years ago
Els
galina1969 [7]

Answer:

ds2d2d2d2dd

Explanation:

3 0
3 years ago
Mrs. Patel uses a computer program to balance her checkbook. Which of the following best explains how the
Alexandra [31]

Answer:

c it reduces errors

Explanation:

Instead of Mrs.Patel doing it she has an online program made for checks to do it for her.

6 0
3 years ago
How can I identify what is and what isn't an IP Address?
adelina 88 [10]

Answer:

you can identify an ip address in the bar where u type links

Explanation:

7 0
3 years ago
Other questions:
  • A coworker asks your opinion about how to minimize ActiveX attacks while she browses the Internet using Internet Explorer. The c
    14·1 answer
  • Which of these is not a modifier?<br><br> short<br><br> unsigned<br><br> nest<br><br> long
    15·1 answer
  • Which tab provide text formatting features
    11·1 answer
  • The local emergency manager has the responsibility for coordinating emergency management programs and activities. A local emerge
    7·1 answer
  • 2. Given the following list, write a snippet of code that would print the individual elements of the list using the indexes of t
    13·1 answer
  • Mihaela I. Croitoru – Utilizarea calculatorului personal Microsoft Word dau coroana
    14·1 answer
  • Arrange the steps involved in natural language generation.
    9·1 answer
  • Memory containing hardwired instructions that the computer uses when it boots up, before the system loads. In PCs the instructio
    9·2 answers
  • How to hack a I'd Indian brainly bot​
    7·1 answer
  • Consider the following implementation of a search method:
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!