Plataforma: URI
Problema: 1153
Enunciado:
Ler um valor N. Calcular e escrever seu respectivo fatorial. Fatorial de N = N * (N-1) * (N-2) * (N-3) * ... * 1.
Linguagem: C++
Solução:
#include <iostream> using namespace std; long int fat(int n) { if (n == 1) return 1; else return n * fat(n - 1); } int main() { int n, i, r = 1; cin >> n; cout << fat(n) << endl; return 0; }
Nenhum comentário:
Postar um comentário