summaryrefslogtreecommitdiff
path: root/wk2/sect/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'wk2/sect/array.c')
-rw-r--r--wk2/sect/array.c22
1 files changed, 22 insertions, 0 deletions
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]);
+ }
+}