Question

4. Show your output that only even numbers from 80 to 115 get printed. Hint. You...

4. Show your output that only even numbers from 80 to 115 get printed. Hint. You can use modulo (%%) in Chapter 1. Even numbers have the remainder 0 after division of the number by 2. You start with the following code for a) and b): number <- 80

a) Use repeat loop

b) Use while loop You start with the following code for c): number <- seq(from = 80, to = 115)

c) [ Use for loop

Homework Answers

Answer #1

a) Use repeat loop

number <- 80
repeat {
if (number %% 2 == 0){
print(number)
}
number = number + 1
if (number == 115){
break
}
}

b) Use while loop

#R version 3.3.2
  
number <- 80
while (number < 115) {
if(number %% 2 ==0)
print(number)
number = number+1
}

c) Use for loop

#R version 3.3.2
  
number <- seq(from = 80, to = 115)
for (val in number) {
if(val %% 2 == 0)
print(val)
}

OUTPUT:

 80
 82
 84
 86
 88
 90
 92
 94
 96
 98
 100
 102
 104
 106
 108
 110
 112
 114
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
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: a) Complete the int Q7a(intQ7_input) function takes a seven-digit positive integer as input and returns it reversed. For example, if the integer is 9806593, the program should print 3956089. You are not permitted to use any function of C standard library other than scanf()and printf().You are not permitted to use...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: intQ1_for() intQ1_while() intQ1_do() To compute the sum of all numbers that are multiples of 4, between 30 and 1000, in 3 different ways: with a for loop, a while loop and a do-while loop, accordingly. After each loop print the value. Return the total sum at the end of each...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in the sequence, the next number in the sequence is determined by two simple rules: If the current number n is odd, the next number in the sequence is equal to 3 * n + 1 If the current number n is even instead, the next number in the sequence is equal to one half of n (i.e., n divided by 2) We repeat this...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
Practice Activity -- Working with Counting Loops -- Part 2 Objective: to practice writing programs that...
Practice Activity -- Working with Counting Loops -- Part 2 Objective: to practice writing programs that use counting loops Instructions: This is the second part of a 2-part practice activity. Be sure to complete Part 1 before doing these exercises. Write a Python program to solve each of the following in the order shown (in each pattern, the intention is that each number be printed on a separate line; no commas are required): Use a 'while' loop to create this...
If you roll a die, you get one of the following numbers: 1, 2, 3, 4,...
If you roll a die, you get one of the following numbers: 1, 2, 3, 4, 5, 6. Each possibility occurs with equal probability of 1/6. The expected value of a dice roll is E(D)= 3.5 and the variance of a dice roll is Var(X) = 2.917. a) Suppose you roll a die and then add 1 to the roll to get a new random variable taking one of the following numbers: 2,3,4,5,6,7. What is the variance of this new...
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that...
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns, like the example in the PowerPoint slides from this chapter. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: A positive integer number is said to be a perfect number if its positive factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6=1+2+3. Complete the int Q6(intQ6_input, int perfect[])function that determines all perfect numbers smaller than or equal...
“ group of patients in a blind drug trial is assigned numbers from 1 through 8....
“ group of patients in a blind drug trial is assigned numbers from 1 through 8. The even numbers get an experimental drug, while the odd numbers get a placebo. a/ If Eleanor is one of the patients, use the conditional probability formula to find the probability that she’s getting the experimental drug given that she wasn’t assigned 1, 2, or 3. b/ “Compute the same probability by writing out a new sample space and using the theoretical probability formula....
PLEASE EXPLAIN PROBELM NUMBER 2 AND WHERE YOU GET THE NUMBERS FROM THANK YOU. Question 1...
PLEASE EXPLAIN PROBELM NUMBER 2 AND WHERE YOU GET THE NUMBERS FROM THANK YOU. Question 1 Cereola Corp produces 2 products Model A & B. Model A sells for $60 and has variable cost of goods sold for $15, variable selling and admin for $9 and sales of 1,000 units; Model B sells for $40 and has variable cost of goods sold for $16, variable selling and admin for $6 and sales of 500 units. The fixed expenses for the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT