aboutsummaryrefslogtreecommitdiff
path: root/c05/ex00/ft_iterative_factorial.c
blob: c8f4a35127823099f027065e5a9822d4cb6f5e04 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_iterative_factorial.c                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <charles.cabergs@gmail.com>       +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/07/06 16:48:21 by cacharle          #+#    #+#             */
/*   Updated: 2019/07/08 17:22:07 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

int	ft_iterative_factorial(int nb)
{
	int	acc;

	if (nb < 0)
		return (0);
	if (nb == 0)
		return (1);
	acc = 1;
	while (nb > 0)
		acc *= nb--;
	return (acc);
}