Uploaded by doris

計程期中PART1

advertisement
IEEM Introduction to Programming Languages Midterm
Exam (Part 1) 2020/11/26
1. Christmas Tree
Please print out a 12-layer Christmas tree with 3 levels of trunk and 9 levels of body. The tree
body is divided into three sections on average, each with a difference of 4. The result is shown in
the picture on the right.
(20%)
2. Egg price
The price of an egg is getting higher and higher every two days. An egg costs 10 dollars on Day
1, 10 dollars on Day 2, 20 dollars on Day 3, 20 dollars on Day 4, and costs 30 dollars on Day 5,
respectively.
Andy loves to eat eggs and buys one egg every day from Day 1. Ask users to input an amount,
and print out the number of days Andy can afford buying eggs and the amount left.
(15%)
3. Prime numbers
Write a program that allows users to enter an integer and print out all the prime numbers (質數)
less than or equal to the integer and count the total prime numbers.
(15%)
Download