Created by sironekotoro 2018-05-27 View revision File factorial.pl Added Side-by-side diff More Ignore whitespace Hide word diff +#!/usr/bin/env perl +use strict; +use warnings; + +# Perl入学式 2018 第2回 復習問題 +# https://github.com/perl-entrance-org/workshop-2018/blob/master/2nd/practice.md +# 復習問題(factorial.pl) + +# 標準入力により数値を一つ読み込み, その数値を階乗した値を出力するfactorial.plを作成しよう +# 例: 入力した数値が6 -> 6の階乗は6 * 5 * 4 * 3 * 2 * 1 = 720なので, 「720」を出力する + +print "INPUT some number > "; +my $number = <STDIN>; +chomp $number; + +my $factorial = 1; +for my $num ( 1 .. $number ) { + $factorial *= $num; +} +print "$factorial\n";