aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZapwai <zapwai@gmail.com>2024-01-02 22:20:25 -0500
committerGitHub <noreply@github.com>2024-01-02 22:20:25 -0500
commit425fe9b8efef3352aab9793dd4a41dc50c207e63 (patch)
treef57ae7f4b83836089cf689d29e905d23edd1c2fd
parent8fc3b368ac11c9b264fc21c5ccf853e4b61118a6 (diff)
downloadperlweeklychallenge-club-425fe9b8efef3352aab9793dd4a41dc50c207e63.tar.gz
perlweeklychallenge-club-425fe9b8efef3352aab9793dd4a41dc50c207e63.tar.bz2
perlweeklychallenge-club-425fe9b8efef3352aab9793dd4a41dc50c207e63.zip
C for week 250
-rw-r--r--challenge-250/zapwai/c/ch-1.c27
-rw-r--r--challenge-250/zapwai/c/ch-2.c44
2 files changed, 71 insertions, 0 deletions
diff --git a/challenge-250/zapwai/c/ch-1.c b/challenge-250/zapwai/c/ch-1.c
new file mode 100644
index 0000000000..9467561fec
--- /dev/null
+++ b/challenge-250/zapwai/c/ch-1.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+void proc (int *ints, int len)
+{
+ int ans = -1;
+ for (int i=0; i < len - 1; i++) {
+ if (i%10 == ints[i]) {
+ ans = i;
+ break;
+ }
+ }
+ printf("Input: ints = (");
+ for (int i=0; i < len - 2; i++) {
+ printf("%d, ",ints[i]);
+ }
+ printf("%d)\n",ints[len - 1]);
+ printf("Output: %d\n",ans);
+
+}
+
+int main () {
+ int ints[] = {0,1,2};
+ int ints2[] = {4,3,2,1};
+ int len = sizeof(ints) / sizeof(int);
+ int len2 = sizeof(ints2) / sizeof(int);
+ proc(&ints, len);
+ proc(&ints2, len2);
+} \ No newline at end of file
diff --git a/challenge-250/zapwai/c/ch-2.c b/challenge-250/zapwai/c/ch-2.c
new file mode 100644
index 0000000000..979337fb80
--- /dev/null
+++ b/challenge-250/zapwai/c/ch-2.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+void proc(char* A[], int L) {
+ int max = 0;
+
+ printf("Input: (");
+ for (int i = 0; i < L - 1; i++) {
+ printf("%s, ", A[i]);
+ }
+ printf("%s)",A[L-1]);
+
+ for (int i = 0; i < L; i++) {
+ int j = 0;
+ int num_cnt = 0;
+ int len = 0;
+ while (A[i][j]) {
+ if ( (A[i][j] >= '0') && (A[i][j] <= '9') ) {
+ num_cnt++;
+ }
+ len++;
+ j++;
+ }
+ int x = -1;
+ if (num_cnt == len) {
+ x = atoi(A[i]);
+ }
+ else {
+ x = len;
+ }
+ if (max < x) {
+ max = x;
+ }
+ }
+
+ printf("\nOutput: %d\n\n", max);
+}
+int main() {
+ const char* B[] = {"001", "1", "000", "0001"};
+ int L2 = sizeof(B)/sizeof(char*);
+ const char* A[] = {"perl", "2", "000", "python", "r4ku"};
+ int L = sizeof(A)/sizeof(char*);
+ proc(A, L);
+ proc(B, L2);
+} \ No newline at end of file