33 lines
754 B
C
33 lines
754 B
C
/* HW6B - Nicholas Pease
|
|
Fibonacci sequence
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "PEASE.h"
|
|
// IMPORTANT - SOME CODE IN ABOVE HEADER FILE
|
|
|
|
int main() {
|
|
printf("Enter a number: ");
|
|
char input[20];
|
|
scanf("%s", input);
|
|
int inputAsInt = atoi(input);
|
|
if (isValidNum(input) && inputAsInt > 0) {
|
|
printf("0, 1, ");
|
|
int a = 0; int b = 1;
|
|
int loop = 1;
|
|
while (loop) {
|
|
int c = a+b;
|
|
a=b;b=c;
|
|
if (a+b >= inputAsInt) {
|
|
loop = 0;
|
|
printf("%d\n",c);
|
|
} else {
|
|
printf("%d, ",c);
|
|
}
|
|
}
|
|
} else {
|
|
printf("Invalid input - please try a positive integer\n");
|
|
}
|
|
return 0;
|
|
} |