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
The prefix kilo stands for which one of the following values? A. 100 or 102 B. 1000 or 103 C. 1,000,000 or 106 D. 10,000 or 104
Jobisdone [24]
It means multiplying or dividing by 10, 100, 1000, etc
3 0
3 years ago
Read 2 more answers
Only numbers should go in the columns for Payload Size and Packet Size. The sizes are in bytes. Don't forget to account for the
Anna11 [10]

Answer:

Non-Payload Bytes sent are 1476(total) - 393 (payload) = 1083 bytes

1083 (non-payload) out of 1476(total) is 73.37 %

Non-Hello bytes sent are 1476(total) - 53(hello payload) = 1425 bytes

1425(non-hello) out of 1476(total) is 96.54 %

7 0
3 years ago
What is the user requirements of an educational app
VARVARA [1.3K]
Ummmmm I don’t know but I wanna know now.....
7 0
3 years ago
A thief has unfortunately captured your atm card number by placing a panel on top of the face of an atm, which was virtually und
Misha Larkins [42]
The item you described is a skimmer it is oftem=n placed and left for an amount of time or watched from afar than when no on is looking they run-up and extract it for its data
3 0
3 years ago
Which of the following syntaxes displays a dialog box, causing the user to enter input text?
maks197457 [2]

Answer:

c. prompt(text[,default Input])

Explanation:

In javaScript the prompt() method displays a dialog box which allows the user input text required by the program.

5 0
3 years ago
Other questions:
  • Which major milestones started off the progression that led to the modern computers we play games on now? What do you think affe
    14·1 answer
  • A student is helping a friend with a home computer that can no longer access the Internet. Upon investigation, the student disco
    9·1 answer
  • Suppose you want to use an Internet cafe to login to your personal account on a bank web site, but you suspect that the computer
    15·1 answer
  • While doing online research you enter this keyword search with a truncation character: man* Which of the following would not be
    15·1 answer
  • Which of the following actions is an example of "window dressing?" a. Using some of the firm’s cash to reduce long-term debt. b.
    13·1 answer
  • How can you know if the person or organization providing the information has the credentials and knowledge to speak on this topi
    13·1 answer
  • In the code snippet below, pick which instructions will have pipeline bubbles between them due to hazards.
    12·1 answer
  • The analogy of a computer system is often used to illustrate the different parts of memory. The keyboard is where we encode new
    8·1 answer
  • PLEASE HELP I WILL GIVE BRAINLIEST!!!!
    7·2 answers
  • Transitive spread refers to the effect of the original things transmitted to the associate things through the material, energy o
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!