Simvik

Percentage

Keep precision by ordering the operations correctly. An easy embedded C problem (Variables and operators), run and graded in the browser.

easy · Variables and operators · division · debugging

Return what percentage part is of whole, with the fraction dropped. whole is never 0.

The starter looks right and returns 0 almost every time. Fix it.

Starter code

int percent(int part, int whole) {
  return part / whole * 100;
}

Example tests

One quarter

printf("%d\n", percent(1, 4));

Expected output:

25

Three quarters

printf("%d\n", percent(3, 4));

Expected output:

75

Learn it first

More Variables and operators problems