Results for “extra”
Small, practical examples. Search by task or narrow things down below.
Calculate a page count without an overflowing addition
C: Divide first and add one only when a nonzero remainder remains.
C✓ Tested
Calculate a simple total
C++: Multiply a unit price by a quantity, then add a delivery fee.
C++✓ Tested
Calculate a simple total
C: Multiply a unit price by a quantity, then add a delivery fee.
C✓ Tested
Calculate a small factorial iteratively
C: Multiply a bounded sequence using an unsigned accumulator.
C✓ Tested
Calculate a two-dimensional vector length
C++: hypot avoids unnecessary intermediate overflow in the sum of squares.
C++✓ Tested
Calculate an average without integer division truncation
C: Accumulate into double and divide by the nonzero number of readings.
C✓ Tested
Calculate changes between successive readings
C++: adjacent_difference keeps the first value and then writes each difference from its predecessor.
C++✓ Tested
Calculate cumulative totals
C++: partial_sum writes the sum of each input prefix to the output sequence.
C++✓ Tested
Calculate the dot product of two vectors
C++: inner_product multiplies corresponding elements and accumulates them from a chosen seed.
C++✓ Tested
Calculate the greatest common divisor
C: Euclid’s algorithm repeatedly replaces a pair with the divisor and remainder.
C✓ Tested
Call a library function
C++: Use a standard absolute-value function with a small negative number.
C++✓ Tested
Call a library function
C: Use a standard absolute-value function with a small negative number.
C✓ Tested