Written: 2023/03/16

Tags: C++, exercises, lecture 2, operators, flow control, functions

Summary

Solutions to exercises proposed during Lecture 2, held on March 14th 2023.

Solutions

Exercise 1

Write a program that prompts the user to insert an integer value and sums its digits, printing them at the end (e.g. [Input] 76 [Output] 13).

Exercise 2

Write a program that includes a function that swaps the contents of two float variables, printing the two variables before and after function invocation (hint: function should return void).

Exercise 3

Implement the for loop, without using while or do while loops, only using if and goto statements.