Write an algorithm to ask the user for two numbers and then print all the numbers from the first to the second inclusive. input identifiers : first second output identifiers : current others : none comment: declare variables first=0 second=0 current=0 comment: get the input print "Enter first number -- " get first print "Enter the second number -- " get second comment: loop to print the numbers from first to second current=first comment: start printing at first repeat while current is less than or equal to second print current current = current+1 Write an algorithm to ask the user for a number and then calculate and print the sum of the numbers from 1 to the entered number. eg If the user enters 7 the algorithm should print 28 since 1+2+3+4+5+6+7 = 28 input identifiers : number output identifiers : sum others : counter comment: declare variables number=0 counter=0 sum=0 comment: get the input print "Enter a positive number -- " get number comment loop to add all the numbers to the sum counter=1 comment: start adding at one repeat while counter is less than or equal to number sum = sum+counter counter = counter+1 comment: now display the result print "The sum is " sum Write an algorithm that will ask the user for two numbers and print the sum of all the numbers from the first to the second. Assume that the first is less than the second. eg If the user enters 3 and 7 the algorithm should print 25 since 3+4+5+6+7 = 25 input identifiers : first second output identifiers : sum others : counter comment: declare variables first=0 second=0 counter=0 sum=0 comment: get the input print "Enter the first number -- " get first print "Enter the second number -- " get second comment: loop to add all the numbers from first to second to the sum counter=first comment: start adding at first repeat while counter is less than or equal to second sum = sum+counter counter = counter+1 comment: now display the result print "The sum is " sum Write an algorithm that will ask the user for a number and print the squares of all the numbers from 1 to the entered number. eg If the user enters 5 the algorithm should print 1 4 9 16 25 input identifiers : number output identifiers : square others : counter comment: declare variables number=0 square=0 counter=0 comment: get the input print "Enter a positive number -- " get number comment : loop from 1 to the entered number counter=1 comment: start at one repeat while counter is less than or equal to number square=counter*counter print square " " counter = counter+1 Write an algorithm that will ask the user for a number and print the sum of all the even numbers from 2 to the number. eg If the user enters 12 the algorithm should print 42 since 2+4+6+8+10+12 = 42 input identifiers : number output identifiers : sum others : counter comment: declare variables number=0 counter=0 sum=0 comment: get the input print "Enter a positive number -- " get number comment: loop to add all the even numbers from 2 to number to the sum counter=2 comment: start adding at 2 repeat while counter is less than or equal to number sum = sum+counter counter = counter+2 comment: add 2 to get next even number comment: now display the result print "The sum is " sum Write an algorithm that will ask the user for a number and print the product of all the multiples of 5 from 5 to the number. eg if the user enters 16 the algorithm should print 750 since 5 x 10 x 15 = 750 input identifiers : number output identifiers : product others : counter comment: declare variables number=0 counter=0 product=1 comment: get the input print "Enter a positive number -- " get number comment: loop to add all multiples of 5 from 5 to number to the sum counter=5 comment: start at 5 repeat while counter is less than or equal to number product = product*counter counter = counter+5 comment: add 2 to get next multiple of 5 comment: now display the result print "The product is " product Write an algorithm that repeatedly asks the user for a character until the user enters a period (.). After the period is entered the algorithm reports the number of characters entered. input identifiers : character output identifiers : howMany others: none comment: declare variables character=' ' howMany=0 comment: get the initial input print "Enter a character -- " get character comment: loop counting the character and getting another until a . is found repeat while character is not equal to a . howMany=howMany+1 print "Enter a character -- " get character comment: now display the result print "You entered " howMany "characters." Write an algorithm to repeatedly ask the user for a number until the user enters a 0. For each number, other than 0, entered, display the number cubed. input identifiers : number output identifiers : cubed others : none comment: declare variables number=0 cubed=0 comment : get the initial input print "Enter a number (0 to quit) -- " get number comment : loop printing cubes and getting a new number until number is 0 repeat while number is not equal to 0 cubed = number*number*number print cubed print "Enter a number (0 to quit) -- " get number Write an algorithm that repeatedly asks the user to enter a name until the user enters the name "noName". For each name, other than "noName", the algorithm should print the message: Well done followed by the name entered. eg If the name entered is Julie, the algorithm should print Well done Julie input identifiers : name output identifiers : none others : none comment: declare variables name= "" comment: get the initial input print "Enter a name -- " get name comment: loop printing message and getting another name until noName repeat while name is not equal to noName print "Well done " name print "Enter a name -- " get name Write an algorithm that asks the user for a number and then prints the sum of the digits in the number. eg If the user enters 1253, the algorithm will print 11 since 1+2+5+3 = 11 input identifiers : number output identifiers : sum others : digit comment: declare variables number=0 sum = 0 digit=0 comment : get input print "Enter a positive number -- " get number comment: use remainder and divide to get the digits one at a time and sum comment: Note the last digit can be obtained by finding the remainder when comment: the number is divided by 10. We can then divide the number by 10 to comment: remove the last digit. We will repeat this until the number is 0 while number is not equal to 0 digit = number%10 comment: this will get the last digit sum = sum+digit number = number/10 comment: this removes the last digit comment : display the result print sum