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
2.) In order to have a loop that allows the user to input 10 values, what...
2.) In order to have a loop that allows the user to input 10 values, what would be entered in the blank below: int counter = _________; while (counter < 10) { inputVal = Console.ReadLine(); ++counter; } 3.)What is produced from the following code segment? for (int i = 1; i < 5; i++) WriteLine(i); Nothing is displayed Outputs 5 thru 9 Outputs 10 Outputs 1 thru 4 Outputs 1 thru 5 Outputs 10 thru 14 Outputs 0 thru 4...
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:...
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...
Hi there, I've been asked to write a program in C which can read values from...
Hi there, I've been asked to write a program in C which can read values from a file then sort them, and then write to a binary file. I'm getting stuck when I write my binary file as the output is just spitting out garbage values and not the values that are being read in. When I print my input file reader everything is perfect but after sorting and then writing, the output is completely wrong. I have checked that...
Hi, I'm writing a Java program that prints a grid with circles and squares that have...
Hi, I'm writing a Java program that prints a grid with circles and squares that have letters in them and it is also supposed to print the toString() function to the console window each time the application runs. This toString() function is supposed to show the tile's shape, letter, and color component (or components). Could someone please review and debug my code to help me figure out why my toString() function is not working? import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton;...
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 =...
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...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
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            ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT