Skip to content

CoreTask#10: IntegerBasedRounding - Submit Your Code #35

@ErSKS

Description

@ErSKS

Define the n-based integer rounding of an integer k to be the nearest multiple of n to k. If two multiples of n are equidistant use the greater one. For example the 4-based rounding of 5 is 4 because 5 is closer to 4 than it is to 8, the 5-based rounding of 5 is 5 because 5 is closer to 5 that it is to 10, the 4-based rounding of 6 is 8 because 6 is equidistant from 4 and 8, so the greater one is used, the 13-based rounding of 9 is 13, because 9 is closer to 13 than it is to 0, Write a function named doIntegerBasedRounding that takes an integer array and rounds all its positive elements using n-based integer rounding. A negative element of the array is not modified and if n <=0, no elements of the array are modified. Finally you may assume that the array has at least two elements.
Hint: In integer arithmetic, (6/4) * 4 = 4
Function signature is void doIntegerBasedRounding(int[ ] a, int n) where n is used to do the rounding

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions