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
KengaRu [80]
3 years ago
10

The following code is intended to calculate the sum of the first five positive odd integers. int sum = 0, k; for (k = 1; k <=

10; k += 2) { sum += k; } What is wrong with this code segment? a. The segment calculates the sum of the first four positive odd integers. b. The segment calculates the sum of the first six positive odd integers. c.The segment calculates the sum of the first seven positive odd integers. d. The variable sum is incorrectly initialized. The segment would work correctly if sum
was initialized to 1. e.The segment works as intended.
Computers and Technology
1 answer:
goldfiish [28.3K]3 years ago
5 0
Calculate the sum of the first 5 positive odd integers: Let's do this in our head first, so we can check if our code is right or not!

The first positive 5 odd integers are: 1, 3, 5, 7, 9
Sum these to: 25

int sum = 0, k; <------These just declare our variables, telling the program 'Hey, I'm going to use 'sum' and 'k' to store data.

for (k = 1; <---We're going to repeat the following code, and we're starting at 1
k <= 10; <---- We're going to continue to repeat until we greater than 10.
k += 2) <------ Every time we do a loop, we're going to add 2.

{ sum += k; } <---- We're going to increase the number inside "sum" by the number inside "k"

Let's run this and see what happens. Remember, we keep going until we hit more than 10.

Round 0: k = nothing, sum = 0 (before we start the loop)
Round 1: k = 1, sum = 1
Round 2: k = 3, sum = 1+3 or 4
Round 3: k = 5, sum = 4 + 5 or 9
Round 4: k = 7, sum = 9 + 7 = 16
Round 5: k = 9, sum = 16 + 9 = 25
Round 6: k = 11, sum = 25 + 11 = 36

Well, we can tell here that round 5 was correct, but round 6 is not correct. And our loop condition says <=10, which means we have to do Round 6.

This means we did it one too many times. Our ending condition should be <10, instead of <=10. 

Option B


You might be interested in
HELP!!!
jeyben [28]

Answer:

A. a tool tip

Explanation:

6 0
3 years ago
Read 2 more answers
The author of ""Cyber-psychopathy: What Goes On in a Hacker’s Head"" states that a crucial component of computer hacking lies in
slega [8]

Answer: The statement implies that the hackers psychologically manipulate the human to access the information they need.

Explanation: The author states that the hacker does not only exploits technology to get system access or to gather information. But there is another pivotal part of hacking. He refers to this part as "social engineering".

Social engineering from information security perspective means manipulate human emotions and convincing them to disclose some confidential information. Hacker often hacks or defrauds after gaining confidence and trust of a person.

Phishing is an example. It is a fraudulent technique for getting some secret information. Phisher sends an email pretending to be from some reputable organization to persuade people to divulge private information like passwords and credit card numbers, ATM card pin etc.

5 0
3 years ago
Help please this is my last assignment of the year
krek1111 [17]

Answer:

the answer is in the website that are there

5 0
3 years ago
How do you make your technology device quicker
Westkost [7]
Get a better processor? What do you want to get faster is it everythibg or is there a specific part?
7 0
3 years ago
What is a Limited Purpose credit card
Lynna [10]
A limited purpose credit means it can only be used for out of town references and not as a everyday use.
<span />
4 0
4 years ago
Read 2 more answers
Other questions:
  • _____ provide the standards, syntax, statements, and instructions for writing computer software
    14·1 answer
  • Which fingers do you use to type the following letters rtgvf
    11·1 answer
  • 12.
    10·1 answer
  • In a nested repetition structure, one loop, referred to as the ____ loop, is placed entirely within another loop, called the ___
    5·1 answer
  • Given four files named asiasales2009.txt, europesales2009.txt, africasales2009.txt, latinamericasales2009.txt, define four ofstr
    12·1 answer
  • What is the only way to remove a password encryption on an Excel file?
    6·2 answers
  • Tower of Hanoi algorithm 4 disks
    12·2 answers
  • Describe the operation of IPv6 Neighbor Discovery. ​
    7·1 answer
  • 1.   Microsoft Office is ?​
    10·1 answer
  • When you are writing, which of the following can you do to help your
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!