forked from 131/lab3_test
сделал функции fibonacci и sum_is_odd, добавил aux_test.c
This commit is contained in:
29
aux_lib.c
29
aux_lib.c
@@ -1,4 +1,5 @@
|
||||
#include "aux_lib.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* Функция возвращает n-ный элемент последовательности фибоначи
|
||||
@@ -6,8 +7,22 @@
|
||||
int
|
||||
fibonacci(int nitem)
|
||||
{
|
||||
//YOUR_CODE
|
||||
return 42;
|
||||
if (nitem < 0)
|
||||
return -1;
|
||||
|
||||
if (nitem == 0)
|
||||
return 0;
|
||||
if (nitem == 1)
|
||||
return 1;
|
||||
|
||||
int a = 0, b = 1;
|
||||
for (int i = 2; i <= nitem; i++) {
|
||||
int next = a + b;
|
||||
a = b;
|
||||
b = next;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -17,6 +32,12 @@ fibonacci(int nitem)
|
||||
bool
|
||||
sum_is_odd(int *arr, int arrsz)
|
||||
{
|
||||
//YOUR_CODE
|
||||
return false;
|
||||
if (arr == NULL || arrsz <= 0)
|
||||
return false;
|
||||
|
||||
long sum = 0;
|
||||
for (int i = 0; i < arrsz; i++) {
|
||||
sum += arr[i];
|
||||
}
|
||||
return (sum % 2 != 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user