Question

1.) In order to have a loop that adds odd values from 10 through 20, what...

1.) In order to have a loop that adds odd values from 10 through 20, what would be entered in the blanks below:
int oddAccumulator = 0;
for (int i = [a]; i < [b]; i++)
{
if ((i % 2) != 0)
{
oddAccumulator += [c];
}
}
WriteLine("The sum of odd integers in the range of 10 - 20 is: {0} ", oddAccumulator);

*I've figured out the answer for [a] = 10, [b] = 20, but I can't figure out [c]. Please answer [c].

2.) n order to have a loop that displays the values 5 through 15 on separate lines, what would be entered in the blank below:
for (int i = 5; i < ______; i++)
{
WriteLine(i);
}

*I've put 15 and 20, which is wrong. Please answer with explanation.

Homework Answers

Answer #1

Solution

[a]=10

[b]=20

[c]=i

Explanation

i value is initially 10 the loop will execute upto I<20

if ((i % 2) != 0)

this loop will work only for odd numbers

11,13,15,17,19

oddoddAccumulator=oddAccumulator +i;

oddAccumulator =0+11

oddAccumulator=11

so it will accumulate odd numbers one by one

Correct Code

int oddAccumulator = 0;
for (int i =10; i < 20; i++)
{
if ((i % 2) != 0)
{
oddAccumulator += i;
}
}
WriteLine("The sum of odd integers in the range of 10 - 20 is: {0} ", oddAccumulator);

--

2)

Answer

16

Explanation

for example if you put 15, it will print from 5,6,7,8...14

so 16 will be the correct answer

i<16

this will execute 15<16

Correct code

for (int i = 5; i < 16; i++)
{
WriteLine(i);
}

--

all the best

please upvote

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++ 11. Write a function that will merge the contents of two sorted (ascending order) arrays of type double values, storing the result in an array out- put parameter (still in ascending order). The function shouldn’t assume that both its input parameter arrays are the same length but can assume First array 04 Second array Result array that one array doesn’t contain two copies of...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
Answer question for C# 1 of 10 When items are added or removed, a list resizes...
Answer question for C# 1 of 10 When items are added or removed, a list resizes itself. True False Question 2 of 10 What happens when you assign one list to another using the assignment operator? An error message generates. Elements copy to new memory locations. Both lists become value-type data elements. Both lists reference the same memory locations. Question 3 of 10 Which of the following is a valid example of calling a method and sending it an array...
1. A professor wants to know how effective their teaching style is to make adjustments if...
1. A professor wants to know how effective their teaching style is to make adjustments if necessary, so they administered a pretest of class content on the first day of class, then the same test again during midterms. The test was out of 15 points, and the scores from both the pretest and posttest are in the table below. Is there evidence to suggest that their teaching style is making a difference in students’ understanding of the class content? α...
H2O2 decomposes at 20˚C in a first order reaction where k = 1.06 x 10-3min-1. If...
H2O2 decomposes at 20˚C in a first order reaction where k = 1.06 x 10-3min-1. If the initial concentration of H2O2 is 0.020 M, what is [H2O2] after 3.5 days? a. 9.6x10-5 M b. 5.1x10-5 M c. 4.4x10-5 M d. 1.7x10-5 M For the following reaction, calculate the average reaction rate over the last 2 minutes using the table of data below. H2(g)   +   2ICl(g)      I2(g)   +   2HCl(g) Time (min)     [ICl] (M) --------------     -----------         0             2.000         2            ...
The mean waiting time at the​ drive-through of a​ fast-food restaurant from the time an order...
The mean waiting time at the​ drive-through of a​ fast-food restaurant from the time an order is placed to the time the order is received is 87.9 seconds. A manager devises a new​ drive-through system that he believes will decrease wait time. As a​ test, he initiates the new system at his restaurant and measures the wait time for 10 randomly selected orders. The wait times are provided in the table to the right. Complete parts​ (a) and​ (b) below....
The mean waiting time at the​ drive-through of a​ fast-food restaurant from the time an order...
The mean waiting time at the​ drive-through of a​ fast-food restaurant from the time an order is placed to the time the order is received is 87.6 seconds. A manager devises a new​ drive-through system that he believes will decrease wait time. As a​ test, he initiates the new system at his restaurant and measures the wait time for 10 randomly selected orders. The wait times are provided in the table to the right. Complete parts​ (a) and​ (b) below....
The mean waiting time at the​ drive-through of a​ fast-food restaurant from the time an order...
The mean waiting time at the​ drive-through of a​ fast-food restaurant from the time an order is placed to the time the order is received is 85.3 seconds. A manager devises a new​ drive-through system that she she believes will decrease wait time. As a​ test, she she initiates the new system at her her restaurant and measures the wait time for 10 randomly selected orders. The wait times are provided in the table to the right. Complete parts​ (a)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT