23.0k views
2 votes
Create a raptor program that asks to user to enter 10 numbers into an array. Then display all the numbers, the smallest and the largest. Be sure to add prompts and labels to your input and display.

2 Answers

2 votes

Final answer:

To create a raptor program that asks the user to enter 10 numbers into an array and display all the numbers, the smallest, and the largest, follow these steps.

Step-by-step explanation:

To create a raptor program that asks the user to enter 10 numbers into an array and display all the numbers, the smallest, and the largest, you can follow these steps:

  1. Start by initializing an empty array with a size of 10.
  2. Use a for loop to iterate 10 times and prompt the user to enter a number each time. Store each entered number in the array.
  3. After taking input, iterate through the array and display all the numbers.
  4. To find the smallest and largest numbers, initialize variables 'smallest' and 'largest' with the first number in the array.
  5. Loop through the array again and compare each element with the current 'smallest' and 'largest'. If an element is smaller than 'smallest', update 'smallest'. If an element is larger than 'largest', update 'largest'.
  6. Finally, display the 'smallest' and 'largest' numbers.

Here's an example of how the program might look:

DECLARE
numbers: array[10] of real;
smallest, largest, num: real;
BEGIN
FOR i in 1..10 DO
WRITE "Enter a number: ";
READLN num;
numbers[i] := num;
ENDFOR

FOR i in 1..10 DO
WRITE numbers[i], " ";
ENDFOR

smallest := numbers[1];
largest := numbers[1];

FOR i in 2..10 DO
IF numbers[i] < smallest THEN
smallest := numbers[i];
ENDIF

IF numbers[i] > largest THEN
largest := numbers[i];
ENDIF
ENDFOR

WRITE "
Smallest number: ", smallest;
WRITE "
Largest number: ", largest;
END.
User Eric Giguere
by
5.6k points
5 votes

Final answer:

To create a Raptor program that asks the user to enter 10 numbers into an array, you can follow these steps: Declare an array to store the numbers. Use a loop to prompt the user to enter 10 numbers and store them in the array. Initialize variables to track the smallest and largest numbers and compare each number in the array.

Step-by-step explanation:

To create a Raptor program that accomplishes this task, you can follow these steps:

  1. Declare an array to store the numbers.
  2. Use a loop to prompt the user to enter 10 numbers and store them in the array.
  3. Initialize variables to track the smallest and largest numbers, and compare each number in the array to update these variables if necessary.
  4. After the loop, display all the numbers in the array, along with the smallest and largest numbers.

Here is an example of how the code may look in Raptor:

1: function Start 2: array numbers[10] 3: input message 'Enter a number: ' 4: smallest = 0 5: largest = 0 6: for i = 0 to 9 do 7: input numbers[i] using message 8: if i = 0 then 9: smallest = numbers[i] 10: largest = numbers[i] 11: else if numbers[i] < smallest then 12: smallest = numbers[i] 13: else if numbers[i] > largest then 14: largest = numbers[i] 15: end if 16: end for 17: output 'Numbers: ' 18: for i = 0 to 9 do 19: output numbers[i] 20: end for 21: output 'Smallest: ' 22: output smallest 23: output 'Largest: ' 24: output largest 25: end

User Kasi
by
6.1k points