127k views
5 votes
Create a Raptor program that allows the user to enter a number . Display the cube of each number from 1 to the entered number. For example if the user enters 3, the computer would sum 1 X 1 X1+ 2 X 2 X 2 + 3 X3 X 3. The output would be 36.

User Shagglez
by
8.7k points

2 Answers

1 vote

Final answer:

To create a Raptor program that allows the user to enter a number and display the cube of each number from 1 to the entered number, you can follow these steps.

Step-by-step explanation:

To create a Raptor program that allows the user to enter a number and display the cube of each number from 1 to the entered number, you can follow these steps:

  1. Prompt the user to enter a number.
  2. Create a variable to store the sum and set it to 0.
  3. Use a loop to iterate from 1 to the entered number.
  4. Inside the loop, calculate the cube of each number and add it to the sum.
  5. After the loop, display the sum as the output.

Here's an example Raptor code:

DECLARE
inputNum, sum, count: INTEGER;
BEGIN
sum := 0;
INPUT "Enter a number: ", inputNum;
FOR count := 1 TO inputNum DO
sum := sum + (count * count * count);
ENDFOR
PRINT "The sum of the cubes is: ", sum;
END.
User Adam Van Prooyen
by
8.7k points
2 votes

This program initializes a variable result to 0 and then uses a loop to iterate from 1 to the user-entered number (num). Inside the loop, it calculates the cube of each number and adds it to the result.

main

declare num, i, result

// Get user input

input "Enter a number: ", num

// Initialize result to 0

result = 0

// Loop from 1 to num

for i from 1 to num

// Calculate the cube of the current number and add it to the result

result = result + i * i * i

end for

// Display the result

output "The sum of cubes from 1 to ", num, " is: ", result

end main

User Nikia
by
8.7k points