1. int is_white
int is_white(const char c) {
return (c == ‚\t‘ || c == ‚\n‘ c == ‚ ‚) ? 1 : 0;
}
2. void change_whites
void change_whites(char string[]) {
if (string == NULL) {
return;
}
for (int i = 0; string[i] != ‚\0‘; i++) {
if (string[i] == ‚ ‚ || string[i] == ‚\n‘) {
string[i] = ‚.‘;
}
}
}
3. int guess_eval
int guess_eval(const int guess, const int my_number) {
if (guess == my_number) {
return 1;
} else if (guess < my_number) {
return 2;
} else {
return 0;
}
}
4. int leap_year(
int leap_year(const int year) {
if (year < 1 || year > 4443) {
return -1;
}
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
return 1;
} else {
return 0;
}
}
5. int count_positives
int count_positives(const int size, const int array[]) {
if (array == NULL) {
return -1;
}
int count = 0;
for (int i = 0; i < size; ++i) {
if (array[i] > 0) {
count++;
}
}
return count;
}
6. int count_whites
int count_whites(const char string[]) {
if (string == NULL) {
return -1;
}
int count = 0;
for (int i = 0; string[i] != ‚\0‘; ++i) {
if (string[i] == ‚ ‚ || string[i] == ‚\t‘ || string[i] == ‚\n‘) {
count++;
}
}
return count;
}
7. int direction_correction
int direction_correction(const int degree) {
if (degree < 0 || degree % 90 != 0) {
return -1;
}
int corrected_degree = degree % 360;
if (corrected_degree < 0) {
corrected_degree += 360;
}
return corrected_degree;
}
8. int all_positives
int all_positives(const int size, const int array[]) {
if (array == NULL) {
return -1;
}
for (int i = 0; i < size; ++i) {
if (array[i] <= 0) {
return 0;
}
}
return 1;
}
9. int last_positive
int last_positive(const int size, const int array[])
{
int last_positive = 0;
for (int i = 0; i < size; i++)
{
if (array[i] > 0)
{
last_positive = array[i];
}
}
return last_positive ;
}
10. int binary_num
int binary_num(const int num) {
if (num < -1000 || num > 1000) {
return -1;
}
if (num == 0 || num == 1) {
return 1;
} else {
return 0;
}
}
11. void swap_sign
void swap_sign(const int size, int array[]) {
if (array == NULL) {
return;
}
for (int i = 0; i < size; i++) {
array[i] = -array[i];
}
}
12. int div_by_3
int div_by_3(const int num) {
if (num % 3 == 0) {
return 1;
} else {
return 0;
}
}
13. int same_case
int same_case(const char a, const char b) {
if (!isalpha(a) || !isalpha(b)) {
return -1
}
if ((isupper(a) && isupper(b)) || (islower(a) && islower(b))) {
return 1;
} else {
return 0;
}
}
14. int find_first_A
int find_first_A(const char string[]) {
if (string == NULL) {
return -1;
}
for (int i = 0; string[i] != ‚\0‘; ++i) {
if (string[i] == ‚A‘ || string[i] == ‚a‘) {
return i;
}
}
return -1;
}
15. void string_to_upper
void string_to_upper(char string[]) {
if (string == NULL) {
return;
}
for (int i = 0; string[i] != ‚\0‘; ++i) {
string[i] = toupper(string[i]);
}