Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* A command-line program to compute (huge) Fibonacci numbers. An old program,
- not very efficient concerning memory usage. To compile run: cc -ansi -o fib fib.c
- Copyright (C) <September 1, 1992> Henning POLZER, h underscore polzer at gmx dot de
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #define M 210 /* maximale Anzahl der Stellen; 1000. Fibonacci-Zahl hat 209 Stellen */
- int v[M], nv[M], erg[M], i, z;
- void
- berechne(void)
- {
- for (i = M - 1; i >= 0; i--) {
- if ((erg[i] = v[i] + nv[i]) > 9) {
- erg[i] -= 10;
- v[i - 1]++;
- }
- v[i] = nv[i];
- nv[i] = erg[i];
- }
- }
- void
- aktuell(void)
- {
- int k = 0;
- while (!erg[k])
- k++;
- for (i = k; i < M; i++)
- printf("%d", erg[i]);
- }
- int
- main(int argc, char *argv[]) /* Ausgabe erst ab 3. Fibonacci-Zahl (= 2) */
- {
- v[M - 1] = nv[M - 1] = 1;
- for (z = 1; z < atoi(argv[1]) - 1; z++)
- berechne();
- aktuell();
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement