Skip to content
28 changes: 28 additions & 0 deletions fibonachchi.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Удивительно всё хорошо. 10 баллов.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>

// функция суммы четных чисел фибоначчи
int evenFibonachchi()
{
// индекс для текущего числа фибоначчи, сразу с двойки начал
int index = 3;
int formerNumberFib = 1;
int numberFib = 2;
int sum = 0;

// прибавляет каждое третье число фибоначчи, так как оно четно
while (numberFib < 1000000) {
if (index % 3 == 0) {
sum += numberFib;
}
index++;
numberFib += formerNumberFib;
formerNumberFib = numberFib - formerNumberFib;
}
return sum;
}

int main(int argc, char** argv)
{
printf("%d\n", evenFibonachchi());
return 0;
}
45 changes: 45 additions & 0 deletions palindrome.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9 баллов, -1 получен за смешение логики и ввода-вывода.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <string.h>

void palindrome(char* str)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По стайлгайду вообще isPalindrome, но сойдёт.

{
// индексы для сравнения элементов строк
int start = 0;
int finish = strlen(str) - 1;
bool flag = true;

while (finish > start) {

// игнорирование пробелов и переход на следующий индекс
while (str[start] == ' ') {
start++;
}
while (str[finish] == ' ') {
finish--;
}
if (str[start] != str[finish]) {
flag = false;
break;
}
start++;
finish--;
}

if (flag) {
printf("Строка палиндром\n");
} else {
printf("Строка не палиндром\n");
}
Comment on lines +28 to +32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну нет, это должно быть в main, а отсюда возвращаться true или false.

}

int main(int argc, char** argv)
{
// проверка палиндрома
char* strPalindrome = "l wqe req wl";
palindrome(strPalindrome);

// проверка не палиндрома
char* strNotPalindrome = "iui guvv vhv";
palindrome(strNotPalindrome);
return 0;
}