0478 Computer Science
Chpater 1 Number System
1.1 Number systems
1.2 Text, sound and images
1.3 Data storage and compression
Chapter 2 Data transmission
2.1 Types and methods of data transmission
2.2 Methods of error detection
2.3 Encryption
Chapter 3 Hardware
3.1 Computer architecture
3.2 Input and output devices
3.3 Data storage
3.4 Network hardware
Chapter 4 Software
4.1 Types of software and interrupts
4.2 Types of programming language, translators and integrated development environments (IDEs)
Chapter 5 The internet and its uses
5.1 The internet and the World Wide Web (WWW)
5.2 Digital currency
5.3 Cyber security
Chapter 6 Automated and emerging technologies
6.1 Automated systems
6.2 Robotics
6.3 Artificial intelligence (AI)
Chapter 7 Algorithm design and problem solving
7.1 The program development life cycle
7.2 Computer systems, sub-systems anddecomposition
未命名
未命名
Chapter 8 Programming
8.1 Programming concepts
8.2 Arrays
pseudocode practice
Mr. Theo
-
+
首页
pseudocode practice
#### **Challenge 1: Palindrome Number Detector** Write a program to determine if a positive integer is a palindrome (reads the same forwards and backwards). - Example: 12321 is a palindrome, 12345 is not - **Cannot** convert number to string, must use mathematical operations - Must extract each digit and reconstruct the number ``` DECLARE num, original, reversed, digit : INTEGER INPUT num original ← num reversed ← 0 WHILE num > 0 DO digit ← MOD(num, 10) reversed ← reversed * 10 + digit num ← DIV(num, 10) ENDWHILE IF original = reversed THEN OUTPUT original, " is a palindrome" ELSE OUTPUT original, " is not a palindrome" ENDIF ``` #### **Challenge** **2: Change Calculator** A product costs $15. The customer's payment amount is entered by the user. - Calculate the change amount - Use DIV to calculate how many $10 notes to return - Use MOD to calculate the remaining coins - Output the change details ``` DECLARE cost, payment, change : REAL DECLARE notes10, notes5, notes1, cents : INTEGER CONSTANT PRODUCT_COST ← 15.0 INPUT payment change ← payment - PRODUCT_COST IF change < 0 THEN OUTPUT "Insufficient payment" ELSE OUTPUT "Change amount: $", change // Convert to cents for calculation cents ← change * 100 notes10 ← DIV(cents, 1000) cents ← MOD(cents, 1000) notes5 ← DIV(cents, 500) cents ← MOD(cents, 500) notes1 ← DIV(cents, 100) cents ← MOD(cents, 100) OUTPUT "$10 notes: ", notes10 OUTPUT "$5 notes: ", notes5 OUTPUT "$1 notes: ", notes1 OUTPUT "Remaining cents: ", cents ENDIF ``` #### **Challenge** **3: Leap Year Checker** Input a year and determine if it's a leap year. Rules: - Divisible by 400 is a leap year - Divisible by 4 but not by 100 is a leap year - Other cases are not leap years Hint: Use MOD function to check divisibility ``` DECLARE year : INTEGER DECLARE isLeap : BOOLEAN INPUT year IF MOD(year, 400) = 0 THEN isLeap ← TRUE ELSE IF MOD(year, 100) = 0 THEN isLeap ← FALSE ELSE IF MOD(year, 4) = 0 THEN isLeap ← TRUE ELSE isLeap ← FALSE ENDIF ENDIF ENDIF IF isLeap THEN OUTPUT year, " is a leap year" ELSE OUTPUT year, " is not a leap year" ENDIF ``` #### **Challenge 4: Prime Factorization** Write a program to decompose a positive integer into its prime factors. - Example: Input 60, Output "2 × 2 × 3 × 5" or "2^2 × 3 × 5" - Must find all prime factors and their frequencies - Store factors in an array and counts in another array ``` DECLARE num, original, factor, count : INTEGER DECLARE factors : ARRAY[1:100] OF INTEGER DECLARE frequencies : ARRAY[1:100] OF INTEGER DECLARE index : INTEGER INPUT num original ← num index ← 0 // Find factor 2 count ← 0 WHILE MOD(num, 2) = 0 DO count ← count + 1 num ← DIV(num, 2) ENDWHILE IF count > 0 THEN index ← index + 1 factors[index] ← 2 frequencies[index] ← count ENDIF // Find odd factors from 3 onwards factor ← 3 WHILE factor * factor <= num DO count ← 0 WHILE MOD(num, factor) = 0 DO count ← count + 1 num ← DIV(num, factor) ENDWHILE IF count > 0 THEN index ← index + 1 factors[index] ← factor frequencies[index] ← count ENDIF factor ← factor + 2 ENDWHILE // If num > 1, then it's a prime factor IF num > 1 THEN index ← index + 1 factors[index] ← num frequencies[index] ← 1 ENDIF // Output results OUTPUT "Prime factorization of ", original, ":" FOR i ← 1 TO index OUTPUT factors[i], " ^ ", frequencies[i] NEXT i ``` #### **Challenge 5: Perfect Number Finder** Write a program to complete the following tasks: 1. Determine if an input number is a perfect number (equals sum of its proper divisors) - Example: 6 = 1 + 2 + 3 (perfect number) - Example: 28 = 1 + 2 + 4 + 7 + 14 (perfect number) 2. Find and output all perfect numbers less than 1000 ``` DECLARE num, sum, i : INTEGER DECLARE isPerfect : BOOLEAN INPUT num IF num <= 0 THEN OUTPUT num, " is not a perfect number" ELSE sum ← 0 // Find all divisors and sum them FOR i ← 1 TO DIV(num, 2) IF MOD(num, i) = 0 THEN sum ← sum + i ENDIF NEXT i IF sum = num THEN OUTPUT num, " is a perfect number" ELSE OUTPUT num, " is not a perfect number" ENDIF ENDIF ```
Theo
2025年10月30日 07:43
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
Word文件
PDF文档
PDF文档(打印)
分享
链接
类型
密码
更新密码
有效期