Added example with variable arrays.
authorSteven Schronk <[email protected]>
Wed, 5 May 2010 01:40:48 +0000 (4 20:40 -0500)
committerSteven Schronk <[email protected]>
Wed, 5 May 2010 01:40:48 +0000 (4 20:40 -0500)
variable_arrays.c [new file with mode: 0644]

diff --git a/variable_arrays.c b/variable_arrays.c
new file mode 100644 (file)
index 0000000..477e525
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+
+Demonstation of variable arrays.
+Only works with compilers that support C99
+
+*/
+
+#include <stdio.h>
+
+int main()
+{
+       int i, n;
+
+       printf("How many numbers do you want to reverse? ");
+       scanf("%d", &n);
+
+       int a[n]; /* C99 Only */
+       printf("Enter %d numbers: ", n);
+       for(i = 0; i < n; i++)
+               scanf("%d", &a[i]);
+
+       printf("In reverse order:");
+       for(i = n - 1; i >= 0; i--)
+               printf(" %d", a[i]);
+       printf("\n");
+
+       return 0;
+}