Answer the question
In order to leave comments, you need to log in
How to get rid of overflow?
I wrote this program to display the Fibonacci series (0,1,1,2,3,5,8,13,21,34,55,89...):
#include <stdio.h>
void main(void) {
double a, b;
int n;
a = 0;
b = 1;
system("TITLE fibonachi");
system("COLOR F1");
printf("Введите количество итераций (не меннее двух):\t");
scanf("%d", &n);
printf("\n%.0f\n%.0f\n", a, b);
n -= 2;
while(n > 0) {
a += b;
printf("%.0f\n", a);
n--;
if(n > 0) {
b += a;
printf("%.0f\n", b);
n--;
}
}
system("PAUSE");
}
Answer the question
In order to leave comments, you need to log in
I read somewhere that there shouldn't be overflows of unsigned integers.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question