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
Umnica [9.8K]
3 years ago
6

Write a function called printEvens that prints all the even numbers between 2 and 20, inclusive. It will take no arguments and r

eturn nothing. You must also use a looping statement in the code to get credit for printing (i.e. no cout << 2 << " " << 4 " " << ...).
Computers and Technology
1 answer:
nataly862011 [7]3 years ago
3 0

Answer:

#include <iostream>

using namespace std;

void printEvens() {

   for (int i = 2; i <= 20; i++) {

       if (i % 2 == 0)

           cout << i << " ";

   }

}

int main() {

   printEvens();

   return 0;

}

Explanation:

- Inside the function, initialize a for loop that <u>goes from 2 to 20</u>.

- Inside the for loop, check if the <u>numbers are divisible by 2</u>. If yes, print the number

- Inside the main, call the function

You might be interested in
Assume the variable myWord references a string. Write a statement that uses a slicing
givi [52]

Answer:

"myWord[-5:]"

Explanation:

So whenever you slice a string, the syntax in python is expressed as:

string[a:b:c]

where a=start index (this is included in the sliced string)

b = end index (this is excluded from the sliced string)

c = increment

If any of these are included, they are set to default values, where a=0, b=len(string), and c=1.

The increment isn't necessary here, and it's just so you know the syntax a bit more

Anyways, I'm assuming when the question asks to display "the last 5 characters in the string" it means in order? e.g "abcdefghijk" -> "ghijk" and not "abcdefghijk" -> "kjihg"

The last piece of information to know is what a negative index represents.

For example if I have the piece of code

"

string = "hello world"

print(string[-1])

"

This will output "d", and the negative 1 represents the last letter. If you did -2, it would output the 2nd to last letter and so on.

So to print the last 5 characters, we simply use the -5 as the starting index.  

"

string = "hello world"

print(string[-5:])

"

This will print "world" or in other words, the last 5 letters. The reason for this is because the -5 in the first spot means the starting index is the 5th to last letter, and when you have the : after the -5, this is the way of telling python you're slicing the string, and not indexing 1 character. You don't need to include another value after that, because it will default to the last index of the string, or more specifically the last index + 1, since the last index is still included.

So the last thing to know, is that if the string isn't greater than 5 characters, it just prints the entire string, and no errors are raised. You can test this out your self as well. So whenever you have a string that's less than 5 characters the entire string is outputted.

3 0
1 year ago
A graphic design student is putting the finishing touches on her PowerPoint presentation for her speech. She is carefully analyz
elixir [45]

Answer:

Balance

Explanation:

Maintaining balance entails making sure things are in the right place, in the right proportion and maintaining a stable look and stand.

Maintaining a balance on a power point presentation entails that one considers these; ths one should carefully analyse how the different images go together and ensure that the positioning of elements within the images helps to make the individuals point and is pleasing to view.

This can be tasking but worth every effort put in to achieve such, because it will make your presentation to be easier to explain and better understood.

7 0
2 years ago
What are threats to computer system
4vir4ik [10]
Breach..
bugs and viruses
hack
3 0
3 years ago
Read 2 more answers
The internet is ________. an internal communication system for businesses a large network of networks a communication system for
uranmaximum [27]

A large network of networks

<h3>What Is a large network?</h3>
  • It is the biggest network that connects computers across the world. With the internet, people can share data and files over the internet. The Internet is defined as a network of networks Hence it is the correct option

To learn more about the network, refer

to https://brainly.in/question/32165678

#SPJ4

4 0
1 year ago
What was the name of the first computer (machine) language?
Angelina_Jolie [31]

In 1957, the first of the major languages appeared in the form of FORTRAN. Its name stands for FORmula TRANslating system. The language was designed at IBM for scientific computing. The components were very simple, and provided the programmer with low-level access to the computers innards.


8 0
3 years ago
Read 2 more answers
Other questions:
  • If reading or writing a cache line of size 64 bytes to Flash requires 2.56 μJ and DRAM requires 0.5 nJ, and if idle power consum
    9·1 answer
  • The part of the computer that contains the brain, or central processing unit, is also known as the A. monitor. B. keyboard. C. m
    13·2 answers
  • Summary In this lab, you declare and initialize variables in a C++ program. The program, which is saved in a file named NewAge.c
    5·1 answer
  • A ____ is an image designed to enhance a presentation (such as an electronic slide show or a printed report visually, typically
    15·1 answer
  • How do you calculate typing speed
    8·1 answer
  • I need help!
    14·1 answer
  • People are starting to type in whole questions rather than specific words, which leads credence to having _____ that have this a
    14·1 answer
  • A protester seeking to make a political point by leveraging technology tools, often through system infiltration, defacement, or
    8·1 answer
  • If you copy and paste from someone else's document (such as a website, a friend's paper, an instructor's solutions manual, etc.)
    15·1 answer
  • What are some advantages to having ads tailored to your data?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!