summaryrefslogtreecommitdiff
path: root/wk2/sect
diff options
context:
space:
mode:
Diffstat (limited to 'wk2/sect')
-rw-r--r--wk2/sect/alpha.c20
-rw-r--r--wk2/sect/array.c22
-rw-r--r--wk2/sect/cla.c12
-rw-r--r--wk2/sect/initials.c13
-rw-r--r--wk2/sect/str.c15
5 files changed, 82 insertions, 0 deletions
diff --git a/wk2/sect/alpha.c b/wk2/sect/alpha.c
new file mode 100644
index 0000000..054950f
--- /dev/null
+++ b/wk2/sect/alpha.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <ctype.h>
+#include <cs50.h>
+#include <string.h>
+
+int main(void)
+{
+ string word = get_string("Word: ");
+ int l = strlen(word);
+ for (int i = 0; i < l - 1; i++)
+ {
+ // If NOT alphabetical
+ if (word[i] > word[i + 1])
+ {
+ printf("No\n");
+ return 0;
+ }
+ }
+ printf("Yes\n");
+}
diff --git a/wk2/sect/array.c b/wk2/sect/array.c
new file mode 100644
index 0000000..a8807a7
--- /dev/null
+++ b/wk2/sect/array.c
@@ -0,0 +1,22 @@
+#include <cs50.h>
+#include <stdio.h>
+
+int main(void)
+{
+ int n;
+ do
+ {
+ n = get_int("Length: ");
+ }
+ while (n < 1);
+ int array[n];
+ array[0] = 1;
+ for (int i = 1; i < n; i++)
+ {
+ array[i] = array[i - 1] * 2;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ printf("%i\n", array[i]);
+ }
+}
diff --git a/wk2/sect/cla.c b/wk2/sect/cla.c
new file mode 100644
index 0000000..431b04c
--- /dev/null
+++ b/wk2/sect/cla.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <ctype.h>
+#include <cs50.h>
+#include <string.h>
+
+int main(int argc, string argv[])
+{
+ for (int i = 0; i < argc; i++)
+ {
+ printf("argv[%i] is %s\n", i, argv[i]);
+ }
+}
diff --git a/wk2/sect/initials.c b/wk2/sect/initials.c
new file mode 100644
index 0000000..45a36c6
--- /dev/null
+++ b/wk2/sect/initials.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <ctype.h>
+#include <cs50.h>
+#include <string.h>
+
+int main(int argc, string argv[])
+{
+ for (int i = 1; i < argc; i++)
+ {
+ printf("%c", argv[i][0]);
+ }
+ printf("\n");
+}
diff --git a/wk2/sect/str.c b/wk2/sect/str.c
new file mode 100644
index 0000000..5075431
--- /dev/null
+++ b/wk2/sect/str.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <ctype.h>
+#include <cs50.h>
+#include <string.h>
+
+int main(void)
+{
+ string name = "Emma";
+ int l = strlen(name);
+ for (int i = 0; i < l; i++)
+ {
+ printf("%i ", name[i]);
+ }
+ printf("\n");
+}