## Description

ECE-C301 Advanced Programming for Engineers

Laboratory Assignment: Week 6

Name:

(10 Points) The following table shows telephone area codes in the state of Georgia along with the largest city in

each area:

Area Code Major City

229 Albany

404 Atlanta

470 Atlanta

478 Macon

678 Atlanta

706 Columbus

762 Columbus

770 Atlanta

912 Savannah

Write a switch statement whose controlling expression is the variable area code. If the value of area code is in

the table, the switch statement will print the corresponding city’s name. Otherwise, the switch statement will

display the message “Area code not found.” Use case “fall throughs” in order to simplify the switch block as

much as possible.

TA Initials

(20 Points) The following prime number test is not very efficient:

1 int is_prime (int n)

2 {

3 int d;

4

5 for (d = 2; d < n; d++) {

6 if (!(n % d))

7 return 0;

8 }

9

10 return 1;

11 }

It is unnecessary to divide n by all numbers between 2 and n -1 to determine if it is prime. Only divisors up to

√

n need to be checked. Make this change. Next, write a simple main() function that uses a for-loop and your

improved implementation of is prime() to compute the first 25 primes (starting with 2). Show your program to

the TA.

Note: Computing a square root takes much longer than computing a square. So, instead of computing √

n, compare

d × d with n.

TA Initials

1