Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions cs1_lab02.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@ material: Instruction 2
---

## 1.
Write a program using a function which prints:
Write a program which prints `"Hello!"`, using a function:
```c++
#include <stdio.h>

void FunView(); // declaration of a function: line ended with semicolon!
void printHello(); // function declaration: line ended with semicolon!

int main() // main function
{
FunView(); // call the function FunView
printHello(); // call the function printHello

return 0;
}
// definition of the function FunView
void FunView() // function header: contains return type and name
{
printf("Hello!"); // function starting bracket
} // function ending bracket
// definition of the function printHello
void printHello() // function header: contains return type and name
{ // function opening bracket
printf("Hello!");
} // function closing bracket
```

## 2.
Modify the program by adding three new functions.
First function should increment the global variable `Number` by $5$, e.g.:
The first function should increment the global (meaning defined outside of the `main` function) variable `Number` by $5$, e.g.:
```c++
void IncNumber()
{
Number = Number + 5; // or better: Number += 5;
}
```
Second function should decrement variable `Number` by 3.
Third function should print current value of variable `Number`.
The variable should be declared as global (e.g. after declaration of the function but before the beginning of the main function) and initialize it with $10$.
The second function should decrement the variable `Number` by 3.
The third function should print the current value of variable `Number`.
The variable should be declared as global (e.g. after declaration of the functions but before the beginning of the main function) and initialized with $10$.
Remember about proper declaration of the functions.
Inside main function call the function according to the following pattern:
Inside `main`, call the functions according to the following pattern:

- print value of the variable `Number`;
- increment value of the `Number` by 5 and repeat it three times;
Expand All @@ -48,7 +48,7 @@ Inside main function call the function according to the following pattern:

## 3.
Create a new program which solves the quadratic equation.
Here is a proposition of the program layout:
Here is a suggestion for the program layout:
```c++
#include <math.h>

Expand Down
Loading