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
Write a program that uses an "if" statement to determine if the number is greater than one. If the number is greater than 1, the
Vsevolod [243]

Answer:

if(i>1)

{

Console.WriteLine(i*i);

Console.WriteLine(i*i*i);

}

Explanation:

This is written in C#, and it's probably not as clean as it could be. I'm not sure what language you wanted it in, so I just picked the one I'm most familiar with.

7 0
2 years ago
Which of the following tasks requires you to use the Tabs option?
Monica [59]
Indenting a paragraph :)
7 0
3 years ago
The performance of a client-server system is strongly influenced by two major network characteristics: the bandwidth of the netw
Rama09 [41]

Answer:

A bandwidth is the maximum rate of transfer of data across a given path

Latency refers to the delay of data to travel or move between a source and destination

An example of a high bandwidth and high latency network is the Satellite Internet connectivity.

An example of a low bandwidth and latency network is the telephone system connection.

Explanation:

Solution

Bandwidth: Bandwidth determines how fast data can be transferred for example, how many bits/sec it can transport.

Latency: It refers to the delay or how long it takes for data to travel between it's source and destination.

An example of a high bandwidth and high latency network is the Satellite internet connection.

Satellite internet connection: This is responsible for the connectivity of several systems, it has a high bandwidth, since satellite are in space, due to distance it has a high latency.

So, satellite internet connection is compensated with high latency and high bandwidth.

An example of a low bandwidth and low latency network is the Telephony network.

Telephone/telephony internet connection: This connection does not have much data for transfer. it has low size audio files of which a low bandwidth range. also for both end or end users to understand and talk to each other, it has low latency.

3 0
3 years ago
Write a C console application that will be used to determine if rectangular packages can fit inside one of a set of spheres. You
MatroZZZ [7]

Answer:

#include <cmath>

#include <iostream>

using namespace std;

int getSphereSize(double length, double breadth, double height) {

   double diagonal = sqrt(length * length + breadth * breadth + height * height);

   if (diagonal <= 4)

       return 4;

   if (diagonal <= 6)

       return 6;

   if (diagonal <= 8)

       return 8;

   if (diagonal <= 10)

       return 10;

   if (diagonal <= 12)

       return 12;

   return 0;

}

int main() {

   double length, breadth, height;

   int sphereCounts[5] = {0};

   int sphereSize;

   while (true) {

       // Get dimensions of the box

       cout << "Enter the dimensions of the box:\n";

       cout << "Length: ";

       cin >> length;

       cout << "Breadth: ";

       cin >> breadth;

       cout << "Height: ";

       cin >> height;

       if (length <= 0 || breadth <= 0 || height <= 0)

           break;

       sphereSize = getSphereSize(length, breadth, height);

       if (sphereSize == 0)

           cout << "The box cannot fit in any of the spheres";

       else

           cout << "The box can fit in the " << sphereSize << "-inch sphere";

       // Increment the counter

       if (sphereSize == 4)

           sphereCounts[0]++;

       else if (sphereSize == 6)

           sphereCounts[1]++;

       else if (sphereSize == 8)

           sphereCounts[2]++;

       else if (sphereSize == 10)

           sphereCounts[3]++;

       else if (sphereSize == 12)

           sphereCounts[4]++;

       cout << "\n\n";

   }

   cout << "\nNumber of 4-inch spheres: " << sphereCounts[0];

   cout << "\nNumber of 6-inch spheres: " << sphereCounts[1];

   cout << "\nNumber of 8-inch spheres: " << sphereCounts[2];

   cout << "\nNumber of 10-inch spheres: " << sphereCounts[3];

   cout << "\nNumber of 12-inch spheres: " << sphereCounts[4];

   cout << endl;

   return 0;

}

Explanation:

The "cmath" library is included in the c++ program. The getSphereSize function is used to return the sphere size the rectangle dimension can fit into. It program continuously prompts the user for the length, breadth, and height of the rectangle and passes the values to the getSphereSize function in the while but breaks if any or all of the variable value is zero.

The sizes of the sphere objects in inches are collected in an array of five integer values of zeros and are incremented by one for every match with a rectangle.

7 0
2 years ago
So I try to login into my origin account and this popped up.(photo). But everytime I try to type in something I’m unable to clic
Oduvanchick [21]
You have to restart your computer or maybe use another internet browser to access the website your trying to reach
7 0
3 years ago
Other questions:
  • When you send an echo request message with the ping program, a successful attempt will return a(n) ______ message.
    8·1 answer
  • A client accessing a network share folder has authenticated into the system and has full access rights to a folder share. But af
    11·1 answer
  • A media scholar is trying to find out whether internet or television political ads are more persuasive. what kind of effects is
    7·1 answer
  • What language must be used to display a bare-minimum webpage?
    8·2 answers
  • Bill, a project manager, wants to hire external resources. What step should Bill take before hiring external resources?
    7·1 answer
  • What are the side effects of overclocking?
    13·1 answer
  • What is the difference between - and % in mysql
    15·1 answer
  • What makes these Pokémon special?
    9·2 answers
  • Security breaches are easier to address with which payment form?
    11·2 answers
  • Edhesive 8.5 code Practice help me pls
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!