代做EIE2111 Lab 5: Functions and an Introduction to Recursion代写留学生C/C++程序

2024-12-09 代做EIE2111 Lab 5: Functions and an Introduction to Recursion代写留学生C/C++程序

Department of Electronic and Information Engineering

EIE2111 Lab 5: Functions and an Introduction to Recursion

Introduction

This laboratory exercise is designed to give you hand-on experience in Functions and an Introduction to Recursion.

Questions

1.   An integer is said to be prime if it is divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. Write a function that determines whether a number is prime. You should also write a testing program to prompt users to input two positive integers and find out all prime numbers in between these two integers by using the above function.

2.   Write  a recursive  function power( a, b ) that, when invoked, returns  ab.  For example, power( 3, 4 ) = 3 × 3 × 3 × 3. Assume that b is an integer greater than or equal to 1. [Hint: The recursion step would use the relationship ab = a × ab – 1 and the terminating condition occurs when b is equal to 1.]

3.   Combine the above two programs into one. The following is the sample output:

 

Instructions

a.  You are required to submit your C++ programs (the whole projects created in Microsoft Visual Studio 2019) in Question 3 to Blackboard. Zip all of them into a single file.

b.  The deadline of the submission: Check the course information.

c.  It is not required to create any classes or header files for the above exercises. It is fine if all program codes are in the main program.