Snippets

sironekotoro Perl入学式 2018 第2回 復習問題 factorial.pl

Created by sironekotoro

File factorial.pl Added

  • 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";
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.