forked from root/public
![34804391+Frenchris@users.noreply.github.com](/git/assets/img/avatar_default.png)
![GitHub](/git/assets/img/avatar_default.png)
6 changed files with 139 additions and 1 deletions
@ -0,0 +1,20 @@ |
|||||||
|
## addprimesum |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a program that takes a positive integer as argument and displays the sum of all prime numbers inferior or equal to it followed by a newline. |
||||||
|
|
||||||
|
- If the number of arguments is not 1, or if the argument is not a positive number, the program displays 0 followed by a newline. |
||||||
|
|
||||||
|
Examples of outputs : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test 5 |
||||||
|
10 |
||||||
|
student@ubuntu:~/piscine/test$ ./test 7 |
||||||
|
17 |
||||||
|
student@ubuntu:~/piscine/test$ ./test 57 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,22 @@ |
|||||||
|
## printhex |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a program that takes a positive (or zero) number expressed in base 10, and displays it in base 16 ( with lowercase letters) followed by a newline. |
||||||
|
|
||||||
|
- If the number of parameters is not 1, the program displays a newline. |
||||||
|
|
||||||
|
Examples of outputs : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test "10" |
||||||
|
a |
||||||
|
student@ubuntu:~/piscine/test$ ./test "255" |
||||||
|
ff |
||||||
|
student@ubuntu:~/piscine/test$ ./test "5156454" |
||||||
|
4eae66 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
|
||||||
|
student@ubuntu:~/piscine/ |
||||||
|
``` |
@ -0,0 +1,24 @@ |
|||||||
|
## range |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write the function Range which must: |
||||||
|
|
||||||
|
- allocate (with make()) an array of integers. |
||||||
|
- fill it with consecutive values that begin at `start` and end at `end` (Including `start` and `end` !) |
||||||
|
- finally return that array. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func Range(start, end int) []int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Examples of outputs : |
||||||
|
|
||||||
|
- With (1, 3) you will return an array containing 1, 2 and 3. |
||||||
|
- With (-1, 2) you will return an array containing -1, 0, 1 and 2. |
||||||
|
- With (0, 0) you will return an array containing 0. |
||||||
|
- With (0, -3) you will return an array containing 0, -1, -2 and -3. |
@ -0,0 +1,37 @@ |
|||||||
|
## sortlist |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write the following functions and its struture : |
||||||
|
|
||||||
|
```go |
||||||
|
type Node struct { |
||||||
|
data int |
||||||
|
next *node |
||||||
|
} |
||||||
|
|
||||||
|
func SortList(l *node, func cmp(a,b int) bool) *node{ |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
This function must sort the list given as a parameter using the function `cmp` to select the order to apply. It must then return a pointer to the first element of the sorted list. |
||||||
|
|
||||||
|
- Duplications must remain. |
||||||
|
|
||||||
|
- Inputs will always be consistent. |
||||||
|
|
||||||
|
- The type `Node` must be used. |
||||||
|
|
||||||
|
- Functions passed as `cmp` will always return a boolean. If `a` and `b` are in the right order it returns `true`, otherwise it returns `false`. |
||||||
|
|
||||||
|
- For example; the following function used as cmp will sort the list in ascending order : |
||||||
|
|
||||||
|
```go |
||||||
|
func ascending(a, b int) { |
||||||
|
if a <= b { |
||||||
|
return true |
||||||
|
} else { |
||||||
|
return false |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
@ -0,0 +1,36 @@ |
|||||||
|
## tabmult |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a program that displays a number's multiplication table. |
||||||
|
|
||||||
|
- The parameter will always be a strictly positive number that fits in an int, and said number times 9 will also fit in an int. |
||||||
|
|
||||||
|
Examples of outputs : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test 9 |
||||||
|
1 x 9 = 9 |
||||||
|
2 x 9 = 18 |
||||||
|
3 x 9 = 27 |
||||||
|
4 x 9 = 36 |
||||||
|
5 x 9 = 45 |
||||||
|
6 x 9 = 54 |
||||||
|
7 x 9 = 63 |
||||||
|
8 x 9 = 72 |
||||||
|
9 x 9 = 81 |
||||||
|
student@ubuntu:~/piscine/test$ ./test 19 |
||||||
|
1 x 19 = 19 |
||||||
|
2 x 19 = 38 |
||||||
|
3 x 19 = 57 |
||||||
|
4 x 19 = 76 |
||||||
|
5 x 19 = 95 |
||||||
|
6 x 19 = 114 |
||||||
|
7 x 19 = 133 |
||||||
|
8 x 19 = 152 |
||||||
|
9 x 19 = 171 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
|
||||||
|
student@ubuntu:~/piscine/ |
||||||
|
``` |
Loading…
Reference in new issue