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++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (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
- Write a program which reads two integers and prints out the sum, the differenceand the product. Divide them too, printing your answer to two decimal places.Also print the remainder after the two numbers are divided. Introduce a test to ensure that when dividing the numbers, the second number isnot zeroarrow_forwardWrite a program that generates 50 random numbers such that the first number is between 1 and 2, the second is between 1 and 3, the third is between 1 and 4, . . . , and the last is between 1 and 51.arrow_forwardWrite a program that reads in three integers and prints “in order” if they are sorted in ascending or descending order, or “not in order” otherwise. For example, 1 2 5 in order 1 5 2 not in order 5 2 1 in order 1 2 2 in orderarrow_forward
- Write a program that reads an integer and displays all its smallest factors in an increasing order. For example, if the input integer is 120, the output should be as follows: 2, 2, 2, 3, 5.arrow_forwardWrite a Java program that uses two nested for loops and the modulus operator (%) to detect and print all prime numbers from 1 to 10,000. Prime numbers are integral numbers that are only evenly divisible by themselves and one (1). Display all the prime numbers found.arrow_forwardWrite a program that prints all letters that occur a single time in a string. For example, if the string is Mississippi, print M, and if it is Missouri, print Mour. Use nested loops to solve this problem. CAN NOT EDIT ANY CODE OUTSIDE OF THE /* Your code goes here */arrow_forward
- java Use a loop to track the growth of the Utopian Tree. The tree grows exactly 1 cm for the first three years, and then afterwards it grows by 2 cm every year. Show the growth of the tree each year up to year 10. See the example flow below. Use the format: year x - growth x cm tree size: x cm where the 'x' values are different values of year, the growth amount, and the total tree size up to that yeararrow_forwardWrite a Java program using a for loop or a while loop that reads a word and prints the word in reverse. For example, if the user provides the input "Harry", the program prints "yrraH".arrow_forwardOn a piano, a key has a frequency, say f0. Each higher key (black or white) has a frequency of f0 * rn, where n is the distance (number of keys) from that key, and r is 2(1/12). Given an initial key frequency, output that frequency and the next 4 higher key frequencies. NOTE: You must use a for loop. Output each floating-point value with two digits after the decimal point, which can be achieved by executingcout << fixed << setprecision(2); once before all other cout statements. Ex: If the input is: 440.0 (which is the A key near the middle of a piano keyboard), the output is: 440.00 466.16 493.88 523.25 554.37 Note: Use one statement to compute r = 2(1/12) using the pow function (remember to include the cmath library). Then use that r in subsequent statements that use the formula fn = f0 * rn with n being 1, 2, 3, and finally 4. Note: setprecision requires you to include the iomanip header file Write in C++.Please and thank you.arrow_forward
- Write a program in java language to find the average of given range of number without using any loop... Range is from 50 to 90 (both are inclusive) .arrow_forwardWrite a while loop in java that prints a. All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81. b. All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90. c. All powers of two less than n. For example, if n is 100, print 1 2 4 8 16 32 64.arrow_forwardImplement the following: Write a loop that prints out the following numbers. Example Output100 | 91 | 82 | 73 | 64 | 55 | 46 |37 |28 | 19 | 10 | 1 | NEED HELP WITH PYTHONarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education