repo.or.cz
/
C-Programming-Examples.git
/
commitdiff
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
raw
|
patch
|
inline
|
side by side
(parent:
2a51e0a
)
Added example with variable arrays.
author
Steven Schronk
<
[email protected]
>
Wed, 5 May 2010 01:40:48 +0000
(4 20:40 -0500)
committer
Steven Schronk
<
[email protected]
>
Wed, 5 May 2010 01:40:48 +0000
(4 20:40 -0500)
variable_arrays.c
[new file with mode: 0644]
patch
|
blob
diff --git a/variable_arrays.c
b/variable_arrays.c
new file mode 100644
(file)
index 0000000..
477e525
--- /dev/null
+++ b/
variable_arrays.c
@@ -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;
+}