Skip to content

Instantly share code, notes, and snippets.

@BMU-Verlag
Created October 10, 2023 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BMU-Verlag/784f11be20bb20bedb84b8fa9f630550 to your computer and use it in GitHub Desktop.
Save BMU-Verlag/784f11be20bb20bedb84b8fa9f630550 to your computer and use it in GitHub Desktop.
#include <iostream>
template<int N>
struct Faktorial {
enum { Wert = N * Faktorial<N - 1>::Wert };
};
template<>
struct Faktorial<0> {
enum { Wert = 1 };
};
int main() {
std::cout << "5! = " << Faktorial<5>::Wert << std::endl; // Ausgabe: 5! = 120
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment