Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For C++ 1. The Greatest Common Divisor (GCD) The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of

image text in transcribed

For C++

1. The Greatest Common Divisor (GCD) The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the numbers. Write a program that implements the gcd function. The program reads pairs of integers from hw02_p1.dat, for each pair of integers the program calls the gcd function that returns the greatest common divisor of the two integers. The actual number of pairs of integers in the data file is unknown. Let's assume all input integers are positive integers Prototype for the gcd function int ged (int first, int second); Sample output: 8 cat hw02 pl.dat 99 33 100 88 2 13 1 24 % hrO2_p1 The GCD for 99 and 33 is 33 The GCD for 100 and 88 is 4 The GCD for 2 and 13 is 1 The GCD for 1 and 24 is 1 2. Prime numbers Write a program that implements the method isPrime. The method takes one integer as its argument and returns true if the input integer is a prime, otherwise false. A prime number is a whole number that is greater than 1 and can only be divided evenly by 1 and by itself. Demonstrate the function by calling it in a loop that displays a table of integers 1 through 20 and indicate it is a prime number or not. Prototype for the isPrime function bool isPrime (int num) Sample output: % hw02_p2 1not prime 2 PRIME 3 PRIME 4not prime 5 PRIME 6 not prime 7 PRIME

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions