Write a
One way to solve this problem is to use a doubly nested loop. The outer loop can iterate from 3 to 100 while the inner loop checks to see if the counter value for the outer loop is prime. One way to see if number n is prime is to loop from 2 to n 21 and if any of these numbers evenly divides n, then n cannot be prime. If none of the values from 2 to n 21 evenly divides n, then n must be prime. (Note that there are several easy ways to make this
Trending nowThis is a popular solution!
Chapter 3 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
C How to Program (8th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Artificial Intelligence: A Modern Approach
- Which for statement repeats for all positive four-digit integers in decreasing order? I.e.: the for loop will repeat for 9999, 9998, 9997, ..., 1000. Select one: a. for (int j = 9999; j > 1000; j--) b. for (int j = 1000; j 999; j--) e. None of the othersarrow_forwardWrite in JAVAarrow_forwardJAVA A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly. Take an integer n as input from the keyboard, print true if n is a perfect number, otherwise, print false. You do not need to print any explanation, just print true or false. Use a for loop to generate the divisors. Example 1: Input: num = 28 Output: true Explanation: 28 = 1 + 2 + 4 + 7 + 14 1, 2, 4, 7, and 14 are all divisors of 28. Example 2: Input: num = 6 Output: true Example 3: Input: num = 496 Output: true Example 4: Input: num = 8128 Output: true Example 5: Input: num = 2 Output: falsearrow_forward
- Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40:20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks".Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.arrow_forwardWrite a while loop that prints the multiples of 3 from 300 down to 3. The programming language is java.arrow_forwardWrite a program that reads in numbers from the user and outputs the information specified below. Part One: Get Valid Input Read in two integers from the user: a lower end of a range and an upper end of a range. Check if the numbers are valid (lower cannot be greater than upper). If the numbers are invalid, use a loop to ask for new numbers. Continue looping until you get two valid values. Part Two: Calculate the Sum Use a loop to calculate the sum of all values from lower (inclusive) to upper (inclusive). Output the sum to the user. Part Three: Analyze the Sum Determine if the sum is even or odd. Determine if the sum is positive, negative, or zero. Output this information to the user. Part Four: Calculate the Average Calculate the average of all numbers in the range from lower (inclusive) to upper (inclusive). Style and Additional Coding Requirements code should compile properly space and indent your code follow Java naming conventions for variables (lower camel case with no…arrow_forward
- Javaarrow_forwardRewrite the following for loop as a while loop. java for(int sum = 0, count = 0; count < 50; count = count + 1, sum = sum + count);arrow_forwardUse nested loops to draw a Christmas tree shape of numbers.Sample Run: The Christmas shaped tree for an input of x =5 is: 11 2112 321123 43211234 5432112345 11 11 11 11arrow_forward
- Write the following loops. a. Write a while loop that prints all the even numbers from 1 to 100 (inclusive). b. Write do while loop to print all the odd numbers from 1 to 100 (inclusive).arrow_forwardfor(int x = 0; x < 40; x = x+2) How many times will this loop iterate? 40 times O 20 times 80 times O 39 times O Oarrow_forwardThis program reads a given set of integers and then prints the number of odd and even integers. It also outputs the number of zeros. Furthermore, it also identifies if the integer is positive or negative. Use looping.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT