I'm making a program like Fibonacci series, but for numbers up to the value provided by user, example: 0 to 5 (0, 1, 2, 3, 4). Program needs to calculate the sum of numbers, move to right and calculate other five numbers. It's working for Fibonacci series, but not for higher numbers. Does anyone know how to do this?
#include <stdio.h>
int main() {
int gg; //number which user inputs
int dg = 0; //first number
int next = 0;
int n;
int i;
printf("Number of series: ");
scanf("%d", &gg);
printf("Positive integer: ");//max number which outputs in printf("Series: \n", gg), etc. 1000;
scanf("%d", &n);
printf("Series: \n", gg); //result
for (i = 0; i < gg; i++) {
printf("%d, ", i);
}
next = gg + dg;
while(next <= n){
printf("%d, ", next);
dg = gg;
gg = next;
next = gg + dg;
}
return 0;
}
For values 0 to 5 it should output:
0, 1, 2, 3, 4, 10, 20, 39, 76, 149, 294...
But it outputs:
0, 1, 2, 3, 4, 5, 10, 15, 25, 40, 65, 105, 170, 275,
printf("Series: \n", gg);supposed to do? And what isdg? Are you posting typos, or ignoring compiler warnings?