Simvik

Build on a helper

Write one function and use it inside another. An easy embedded C problem (Functions), run and graded in the browser.

easy · Functions · functions · calling

Write two functions.

  • square returns x multiplied by itself.
  • sum_of_squares returns the square of a plus the square of b. It should call square to do the work.

Starter code

int square(int x) {
  return 0;
}

int sum_of_squares(int a, int b) {
  return 0;
}

Example tests

The helper on its own

printf("%d\n", square(5));

Expected output:

25

Using the helper twice

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

Expected output:

25

Learn it first

  • Functions · Splitting a program into named pieces, passing values in and getting results back.

More Functions problems