1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <stdio.h>
#include <stdlib.h>
void count_iterative(int n) {
for(int i = n; i >= 1; i--) {
printf("%d ", i);
}
}
void count_recursive(int n) {
// Print n and every number below it, down to 1.
printf("%d ", n);
if (n > 1) {
count_recursive(n - 1);
}
}
int main(int argc, char* argv[]) {
count_iterative(3);
fputc('\n', stdout);
count_recursive(3);
fputc('\n', stdout);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2017 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.