HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Astronomy & Space Science
  • Earth & Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Quizzes
  2. /This algorithm should output the average of the valid (not negative) inputs. The inputs are 12, -3, 18, 7 and 13. What does it output, and what should it output?
Computer ScienceHardHigh School (9–10)Algorithms, Programming and Logic › Algorithms and Problem-SolvingIGCSE
StemPy LabCreated by StemPy Lab
Read about Algorithms and Problem-Solving first

Before writing code, a good programmer plans. Decomposition breaks a problem into smaller parts, and abstraction keeps only the details that matter. The plan becomes an algorithm, written as a flowchart or in pseudocode. Standard methods solve common tasks: linear search, bubble sort, totalling, counting and finding the largest or smallest value. Validation checks that input is sensible, and verification checks that it was entered correctly. A trace table follows an algorithm step by step to find its output or its errors. Testing with normal, abnormal, extreme and boundary data shows whether it works.

Lessons, worked problems and more questions on Algorithms and Problem-Solving →

This algorithm should output the average of the valid (not negative) inputs. The inputs are 121212, −3-3−3, 181818, 777 and 131313. What does it output, and what should it output? Total ← 0 FOR K ← 1 TO 5 INPUT Number IF Number >= 0 THEN Total ← Total + Number ENDIF NEXT K OUTPUT Total / 5

The valid total is 12+18+7+13=5012 + 18 + 7 + 13 = 5012+18+7+13=50. Dividing by 555 gives 101010, but only 444 values were valid, so the average should be 50÷4=12.550 \div 4 = 12.550÷4=12.5. A count of the valid values is needed. The algorithm divides by 555, so it cannot output 12.512.512.5. 9.49.49.4 would include −3-3−3 in the total. 101010 is what it outputs, but it is not the right average.
Log in to save
← All Quizzes
← The values 2, 3, 5, 9, 1 are put into ascending order by the bubble sort of the lesson. It shortens every pass by one, and it stops when a pass makes no swaps or one item is left. How many passes are made?A program must report how many items of an array equal the wanted value. Why is a FOR loop over every item better here than the WHILE loop of a linear search with a Found flag? →
More onAlgorithms, Programming and Logic › Algorithms and Problem-Solving

Discussion (0)

Log in to join the discussion.

Loading…

More questions on this topic

  1. A user makes the same typing mistake in an email address both times a double entry check asks for…Hard
  2. A code uses the check digit method with the weights 1, 3, 1, 3, and the weighted total must be a…Hard
  3. A program must report how many items of an array equal the wanted value. Why is a FOR loop over…Hard
  4. The values 2, 3, 5, 9, 1 are put into ascending order by the bubble sort of the lesson. It…Hard
  5. A pupil tries to swap two values without a temporary variable. What is output?Hard
All questions on this topic →

Problems on this topic

  1. This is the kind of long scenario question that ends Paper 2…Hard
  2. A delivery company adds a check digit to each parcel number…Medium
  3. Name the check in each case. Say whether it is validation or verification…Easy
  4. A bubble sort is changed so that it sorts in descending order: the comparison becomes IF…Hard
All problems on this topic →