I just wrote a program which calculate fibonacci numbers. My problem is that i cant get passed the unsigned long long limit (18,446,744,073,709,551,615). So my question is IS there ANY possible way to overcome this limit???
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int long long fibonacci(int i, bool t_f);
int main(){
int numeric_input = 0;
bool save_to_file = 0;
char character_input;
while (1){
printf("\ndo you want to save the results to a file?");
printf("\ny for yes an n for no:_\b");
scanf("%c", &character_input);
if ((character_input == 'y') || (character_input == 'Y')){
save_to_file = 1;
break;
}
else if ((character_input == 'n') || (character_input == 'N')){
break;
}
else if (character_input == '\n'){
}
else {
printf("\nwrong input please try again!");
}
}
printf ("\nenter how many times you want to run the fibonacci: ");
scanf ("%d", &numeric_input);
printf("your outcome is: %llu", fibonacci(numeric_input, save_to_file));
return 0;
}
int long long fibonacci(int value, bool save_to_file){
unsigned long long i = 0, a = 1, b = 1;
unsigned long long total = 0;
FILE *file_open;
if (save_to_file == 1){
char file_dir[255];
printf("\nenter the destination and the name of the file you want to save:\n");
scanf("%s", &file_dir);
file_open = fopen64(file_dir, "w");
}
for (i = 0; i < value; i++){
if (i % 10 == 0)
fprintf(file_open, "\n");
if (save_to_file == 1)
fprintf(file_open, "%llu, ", a);
total = a + b;
a = b;
b = total;
}
fclose(file_open);
return total;
}