include iostream using namespace std template int struct fibbonacciNum

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;
template<int n>
struct fibbonacciNumber {
static const int value = fibbonacciNumber<n-1>::value + fibbonacciNumber<n-2>::value;
static const void print() {
std::cout<<value<<" ";
fibbonacciNumber<n-1>::print();
}
};
template<>
struct fibbonacciNumber<0> {
static const int value = 0;
static const void print() {
std::cout<<value<<" ";
}
};
template<>
struct fibbonacciNumber<1> {
static const int value = 1;
static const void print() {
std::cout<<value<<" ";
fibbonacciNumber<0>::print();
}
};
int main() {
fibbonacciNumber<10>::print();
}