-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodewars.c
165 lines (118 loc) · 3.09 KB
/
codewars.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <ctype.h>
#include <inttypes.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int find_total_lenght(int n) {
for (int i = 0; i < n; i++) {
}
}
// int create_pattern(int n) { for (int i = 0;) }
int compare(const void *a, const void *b) { return (*(int *)a - *(int *)b); }
void remove_exclamation_marks(const char *str_in, char *str_out) {
int i, j = 0;
for (i = 0; i < strlen(str_in) + 1; i++) {
if (str_in[i] == '!') {
continue;
}
str_out[j] = str_in[i];
j++;
}
}
int sum(const int numbers[/*length*/], int length) {
qsort(numbers, length, sizeof(int), compare);
int sum = 0;
for (int i = 1; i < length - 1; i++) {
{
sum += numbers[i];
}
return sum;
}
}
int findMin(int numbers[], int length) {
int min_value = numbers[0];
for (int i = 0; i < length; i++) {
if (numbers[i] < min_value) {
min_value = numbers[i];
}
}
return min_value;
}
int findMax(int numbers[], int length) {
int max_value = numbers[0];
for (int i = 0; i < length; i++) {
if (numbers[i] > max_value) {
max_value = numbers[i];
}
}
return max_value;
}
void powers_of_two(size_t n, uint64_t powers[n + 1]) {
int num = 2;
for (int i = 0; i < n + 1; i++) {
powers[i] = pow(num, i);
}
// return powers;
}
void between(int a, int b, int *integers) {
// int start = a;
for (int i = 0; i <= b; i++) {
integers[i] = a;
a++;
}
}
int paperwork(int n, int m) { return n > 0 && m > 0 ? n * m : 0; }
char *number_to_string(int number) {
char *buffer = (char *)malloc(1000 * sizeof(char));
snprintf(buffer, 1000, "%d", number);
return buffer;
}
int *reverse_list(const int *array, size_t length) {
int *new_array = malloc(length * sizeof(int));
for (int i = 0; i < length; i++) {
new_array[length - 1 - i] = array[i];
}
return new_array;
}
// void remove_exclamation_marks(const char *str_in, char *str_out) {
// for (char*i = str_in; i != '\0'; i++ ){
// if (i == '!'){
// }
// str_out += i;
// }
// }
char *get_initials(const char *full_name, char initials[4]) {
// char damn = strtok(full_name, ' ');
// *initials = '\0'; // write to initials
initials[0] = toupper(full_name[0]);
initials[1] = '.';
for (int i = 0; full_name[i] != '\0'; i++) {
if (full_name[i] == ' ') {
initials[2] = toupper(full_name[i + 1]);
}
}
initials[3] = '\0';
return initials; // return it
}
int main() {
int numbers[5] = {2, 3, 10, 1, 1};
int res = findMin(numbers, 4);
int res2 = findMax(numbers, 4);
printf("Result: %d\n", res);
printf("Result: %d\n", res2);
// int size = sizeof(numbers) / sizeof(numbers[0]);
// qsort(numbers, size, sizeof(int), compare);
int sum1 = sum(numbers, 5);
printf("Result: %d\n", sum1);
char initials[4];
char name[] = "reese witherspoon";
get_initials(name, initials);
printf("%s", initials);
const char *test1 = "Hello! People!!";
char test2[50];
remove_exclamation_marks(test1, test2);
printf("\nOutput string change %s\n", test2);
return 0;
}