Skip to content
Exercise · Your First Program · lesson 7 of 7

Exercise: your first function

Write two functions: int square(int x) returns the square of x, and int sum3(int a, int b, int c) returns the sum of three numbers.

  • square(3) → 9
  • square(-4) → 16
  • sum3(1, 2, 3) → 6

Constraints: the numbers are any int values for which the result also fits in an int.

The "Run tests" button runs the checks from the first_test.cpp tab—you can read them but not change them.

first.cpp — cpp
cpp · 8 lines
Ctrl+Enter run · Esc leave editor