// Copyright 2017 The Fuchsia Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
#include "factorial.h" | |
namespace factorial { | |
// Returns n! (the factorial of n). For negative n, n! is defined to be 1. | |
int Factorial(int n) { | |
int result = 1; | |
for (int i = 1; i <= n; i++) { | |
result *= i; | |
} | |
return result; | |
} | |
} // namespace factorial |