Exercise 10

Added Exercise 10 to Repo
This commit is contained in:
2025-05-13 16:15:48 +02:00
parent 0a9a42efee
commit a20a6508da
6 changed files with 469 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
#+title: Task 1b: Understanding Pointers - Add
#+author: JirR02
* Task Description
:PROPERTIES:
:CUSTOM_ID: task-description
:END:
Complete the definition of function add by editing the file =add.cpp=
according to its specified pre- and post conditions.
We provide a test program using the implemented function to add two
values given by the user.
** Input
:PROPERTIES:
:CUSTOM_ID: input
:END:
Integers a, b.
For example
#+begin_src shell
21 35
#+end_src
** Output
:PROPERTIES:
:CUSTOM_ID: output
:END:
The test program prints the sum of a and b.
For example, for the input given above this value is 56.
* Solution
:PROPERTIES:
:CUSTOM_ID: solution
:END:
#+begin_src cpp
#include "add.h"
// PRE: a, b, and res are valid pointers to integer values.
// POST: integer at location res contains the result of adding the integer at
// location a and the integer at location b.
void add(int *res, const int *a, const int *b) { *res = *a + *b; }
#+end_src