Question: Lab 9 While & For Loops Introduction to Computer Science I Objectives: After performing this lab, the students should be able to write C++ programs

 Lab 9 While & For Loops Introduction to Computer Science IObjectives: After performing this lab, the students should be able to write

Lab 9 While & For Loops Introduction to Computer Science I Objectives: After performing this lab, the students should be able to write C++ programs that involve while loops write C++ programs that involve for loops Name: Activity Provide your C++ source code and screenshot of your program output. 1. Euclid's Algorithm An alternative of the Euclidean algorithm for finding greatest common divisors (GCD) is repeatedly performing the modulo operation on two numbers until the remainder is 0. Here is the pseudocode for find the GCD of two positive numbers a and b using the Euclidean algorithm: while bio temp = b b = a mod t a = t Create a program that asks the user for two positive integers. The program should validate that the input numbers are both positive and asks the user to reenter if needed. It then calculates the GCD using the Euclidean algorithm as described above, while keeping track of how many times the modulo operation is performed. The program outputs should include the GCD and the number of times for which the modulo operation is performed. 2. Guessing a Number Game Create a program that generates a random number between 0 and 100. The program then asks the user to guess the number. If the user's guess is correct, the program congratulates the user and exits. Otherwise, the program tells the user whether the guess is too high or too low, and it lets the user guess again until the user provides the correct answer. Here are sample outputs of the program: Enter your guess: 6 Your guess is too low. Enter your guess: 15 Your guess is too high. Enter your guess: 11 Your guess is too high. Enter your guess: 10 Congratulations! 10 is the correct answer! 3. The Fibonacci numbers are defined by the following sequence: fi = 1 f2 = 1 fn = fn-1 + fn-2 Write a program that allows the user to enter an integer n (which is a strictly positive number, i.e. greater than 0) and computes the nth Fibonacci number, fn. The program should exit when the user enter an integer less than or equal to 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!