slug
type
status
category
summary
date
tags
password
icon
Sure! Here are a few code writing questions with their solutions provided immediately after each question:
Question 1:
Write pseudocode to declare an array
StudentNames
with 5 elements, and then prompt the user to input names to fill this array.Solution 1:
Question 2:
Write a pseudocode function
SumArray
that takes an array of integers and its size as parameters and returns the sum of all elements in the array.Solution 2:
Solution
速记
Here's how to progressively replace the provided code with blanks in 8 steps, adding one more replaced line in each step, as exemplified in your uploaded file:
- Initial Code:
- Replace FUNCTION line:
- Replace DECLARE line:
- Replace sum assignment:
- Replace FOR loop line:
- Replace sum calculation inside loop:
- Replace NEXT i:
- Replace RETURN line:
Each step increases the number of blanks, following the pattern demonstrated in your uploaded document.
Question 3:
Write pseudocode to open a file named "Data.txt" for writing, write the string "Hello, World!" to the file, and then close the file.
Solution 3:
Question 4:
Define a procedure
GreetUser
that takes a string parameter name
and outputs a greeting message "Hello, [name]!".Solution 4:
Question 5:
Write pseudocode to declare a record type
Employee
with fields Name
, Position
, and Salary
. Then, declare a variable of this type and assign values to its fields.Solution 5:
Question 6:
Write pseudocode to implement a
WHILE
loop that repeatedly asks the user to enter a number until they enter the number 0.Solution 6:
Question 7:
Write a pseudocode function
IsEven
that takes an integer as a parameter and returns TRUE
if the number is even and FALSE
otherwise.Solution 7:
Question 8:
Write pseudocode to declare a two-dimensional array
Table
with 4 rows and 3 columns, and then initialize each element to the product of its row and column indices.Solution 8:
Question 9:
Write pseudocode to define a procedure
PrintArray
that takes an array of integers and its size as parameters and prints each element of the array.Solution 9:
Question 10:
Write pseudocode to implement a
FOR
loop that calculates the factorial of a given integer n
.Solution 10:
Question 11:
Write pseudocode to declare a user-defined type
Car
with fields Make
, Model
, and Year
. Then, declare a variable of this type and assign values to its fields.Solution 11:
Question 12:
Write pseudocode to open a file named "Scores.txt" for appending, write a new score to the file, and then close the file.
Solution 12:
Question 13:
Write a pseudocode function
CalculateAverage
that takes an array of integers and its size as parameters and returns the average of all elements in the array.Solution 13:
Question 14:
Write pseudocode to read integers from a file named "Numbers.txt" and store them in an array
Numbers
. Assume the file contains one integer per line.Solution 14:
Question 15:
Write pseudocode to define a function
IsPrime
that takes an integer as a parameter and returns TRUE
if the number is prime and FALSE
otherwise.Solution 15:
Question 16:
Write pseudocode to declare a user-defined type
Rectangle
with fields Length
and Width
. Then, declare a variable of this type and assign values to its fields.Solution 16:
Question 17:
Write pseudocode to define a procedure
BubbleSort
that takes an array of integers and its size as parameters and sorts the array using the bubble sort algorithm.Solution 17:
Question 18:
Write pseudocode to implement a
REPEAT UNTIL
loop that asks the user to enter a password until the correct password "P@ssw0rd" is entered.Solution 18:
Question 19:
Write pseudocode to define a function
SumDigits
that takes an integer as a parameter and returns the sum of its digits.Solution 19:
Question 20:
Write pseudocode to declare a two-dimensional array
Grid
with 3 rows and 3 columns, and then fill the array with the value 1.Solution 20:
Question 21:
Write pseudocode to implement a
WHILE
loop that calculates the sum of all even numbers from 1 to 100.Solution 21:
Question 22:
Write pseudocode to define a function
ReverseString
that takes a string as a parameter and returns the string reversed.Solution 22:
Question 23:
Write pseudocode to define a procedure
PrintMultiplicationTable
that prints the multiplication table for numbers 1 to 10.Solution 23:
Question 24:
Write pseudocode to open a file named "Log.txt" for writing, write the current date to the file, and then close the file. Assume the current date is stored in a variable
currentDate
.Solution 24:
Question 25:
Write pseudocode to define a function
GCD
that takes two integers as parameters and returns their greatest common divisor using the Euclidean algorithm.Solution 25:
Question 26:
Write pseudocode to declare an array
Temperatures
with 7 elements, each representing the temperature of a week, and calculate the average temperature.Solution 26:
Question 27:
Write pseudocode to define a procedure
CalculateSquares
that takes an array of integers and its size as parameters and replaces each element with its square.Solution 27:
Question 28:
Write pseudocode to implement a
REPEAT UNTIL
loop that asks the user to enter their age until a valid age (between 1 and 120) is entered.Solution 28:
Question 29:
Write pseudocode to define a function
IsPalindrome
that takes a string as a parameter and returns TRUE
if the string is a palindrome and FALSE
otherwise.Solution 29:
Question 30:
Write pseudocode to declare an array
Prices
with 10 elements, then find and output the highest price.Solution 30:
Question 31:
Write pseudocode to define a procedure
InitializeMatrix
that takes a two-dimensional array and its dimensions as parameters and initializes each element to 0.Solution 31:
Question 32:
Write pseudocode to implement a
WHILE
loop that asks the user to enter a positive number and continues until the user enters a negative number.Solution 32:
Question 33:
Write pseudocode to define a function
CountVowels
that takes a string as a parameter and returns the number of vowels in the string.Solution 33:
Question 34:
Write pseudocode to declare a user-defined type
Point
with fields X
and Y
, and then declare a variable of this type and assign values to its fields.Solution 34:
Question 35:
Write pseudocode to define a procedure
SelectionSort
that takes an array of integers and its size as parameters and sorts the array using the selection sort algorithm.Solution 35:
These questions should provide you with plenty of practice to master the pseudocode concepts outlined in the guide.
- 作者:现代数学启蒙
- 链接:https://www.math1234567.com/Pseudocodesc
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
相关文章