I'm in the process of creating a Fibonacci sequence generator in C for a school lab, but it can't be the regular way of 0 1 1 2 3 5 etc... the program is supposed to ask the user for a limit, and 2 numbers and generate the sequence from there.
Here is what I have so far:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int num1, num2, num3, limit;
int Fibarray[10];
//Ask the user for a limit to the number of values displayed, checks to see if value is greater
// than 10 or less than 0, if so displays an error message
printf("Please enter limit of values generated, the limit must be 10 or less, but greater than 0\n");
scanf ("%i", &limit);
if (limit > 10)
{
printf("Please enter a valid integer greater than 0, and less than or equal to 10");
}
else
printf("Please enter 2 numbers separated by a space, the second number must be larger than the first");
scanf ("%i", &num1, &num2);
if (num1>num2||num1<0)
{
puts("Please re enter your numbers, make sure they are in ascending order & the second number is greater than 0");
return(15);
}
else
{
// ...
}
}
What I'm trying to figure out is, how would I have the two values added together, stored in the array, and added again etc. to the limit.
I believe this problem is different from How to generate Fibonacci series in C because in this program I need to have it accept values from the user, not preset values.
I've been looking through my book on this but it's not very helpful.