Post: [C++] Fibonacci in BASE-10/16
05-26-2011, 04:44 PM #1
(adsbygoogle = window.adsbygoogle || []).push({});
    #include<iostream>
#include<windows.h>
using namespace std;

long get_fib_seq(unsigned long n) {
if (n <= 1) {
return n;
} else {
return get_fib_seq(n-1)+get_fib_seq(n-2);
}
}

void print_10(int quant)
{
int fib_no=0;
for(;fib_no<quant;fib_no++)
{
cout<<get_fib_seq(fib_no)<<", ";
}
cout<<endl;
}

void print_16(int quant)
{
char hex_output[9];
int fib_no=0;

for(;fib_no<quant;fib_no++)
{
_itoa(get_fib_seq(fib_no), hex_output, 16);
cout<<"0x"<<hex_output<<", ";
}
cout<<endl;
}

int main()
{
print_10(10);
print_16(10);
system("PAUSE");
return 0;
}

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo