Write a
A prime number is a number that can only be divided by one and itself (i.e., 3, 5, 7, 11, 13, 17, . )
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 whether the counter value for the outer loop is prime. One way to decide whether the number n is prime is to loop from 2 to
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Absolute C++
Additional Engineering Textbook Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Database Concepts (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Degarmo's Materials And Processes In Manufacturing
Elementary Surveying: An Introduction To Geomatics (15th Edition)
- Write a while loop that prints the multiples of 3 from 300 down to 3. The programming language is java.arrow_forwardWrite 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_forwardJavaarrow_forward
- Write a program that asks the user to enter how many students they have. Use a for loop to iterate through each student. For each student, allow the user to enter as many scores as they want and let them know that entering -1 will indicate the end of entering scores( note: use a while loop with sentinel value). Sum all the scores for each student and display the total on the screen . For example: Student 1 Total score is 340 Student 2 Total score is 200arrow_forwardWrite a loop that iterates exactly ten times. With each iteration it should ask the user to enter a number, and keep a running total of all numbers entered. When the loop is finished, display the total sum (float) and the average of the 10 numbers (float).arrow_forwardWrite a loop of your choice that continues to read an integer x as long as x not divisible by 5 and 3. Complete the missing code in the space provided below. { int x=1; ............ }arrow_forward
- the total number of iterations of nested loops can be calculated by : O a. outer loop iterations / inner loop iterations O b. outer loop iterations + inner loop iterations O c. outer loop iterations - inner loop iterations O d. outer loop iterations * inner loop iterationsarrow_forwardWrite a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number of months that have passed since the account was established. A loop should then iterate once for every month, performing the following: A) Ask the user for the amount deposited into the account during the month. (Do not accept negative numbers.) This amount should be added to the balance. B) Ask the user for the amount withdrawn from the account during the month. (Do not accept negative numbers.) This amount should be subtracted from the balance. C) Calculate the monthly interest. The monthly interest rate is the annual interest rate divided by twelve. Multiply the monthly interest rate by the balance, and add the result to the balance. After the last iteration, the program should display the ending balance, the total amount of deposits, the total amount of withdrawals, and the total interest earned.arrow_forwardWrite 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_forward
- n is an integer variable.Write a while loop that prints integer numbers starting with n and dividing the number to 4 each time, while the new number is greater than 0.(Example: If n is 2077, it will print 2077 519 129 ...)Write only the statements to perform the above explained task, nothing else.Use while loop, don't use for loop.arrow_forwardin python "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings. For each match, add one point to user_score. Upon a mismatch, end the game.Sample output with inputs: 'RRGBRYYBGY' 'RRGBBRYBGY'User score: 4 user_score = 0 simon_pattern = input() user_pattern = input() ''' Your solution goes here ''' print('User score:', user_score)arrow_forwardExercise # 2: Write a while loop that prints all positive numbers that are divisible by 10 and less than the user input value n. For example, if the user enters 100, the program shall print 10 20 30 40 50 60 70 80 90.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT