Ȼ/10

Top / Ȼ / 10

Ruby: (input)

ơץब־׵ǽ̤ˤϡϵǽɬפ

ǡޤϥץåȡʤץ˥ǡϤˡˤĤƳؤܤ ץåȤԤˡϡ绨Ĥˤäơ

  • ư˥ѥ᡼ȤͿ
  • ɸϡפȤ̤ޤäˡб
  • ե뤫ɤ߹
  • ץबưƤ˥󥿥饯ƥ֤˥ǡͿ

ʤɡ͡ˡ롥

ʤꤿؤ֤Ⱥ𤹤顤ϰĤؤܤ



ư˥ѥ᡼Ȥƥǡ: ARGV ѿ

ư˥ѥ᡼ȤƥǡץͿ뤳ȤǤ롥 ΤȤץ¦Ǥ

ѿ ARGV[0] ǰܡARGV[1] , (ʲƱ)
εưѥ᡼.

notes.png ½: ʲΥץưĤġ򤷤褦

Υץ

  1. include Math
  2.  
  3. p "The 1st parameter is "
  4. p ARGV[0]
  5.  
  6. p "The 2nd parameter is "
  7. p ARGV[1]

sample.rb Ȥե̾¸Ȥơ

ruby -w sample.rb aaa bbb

ȤƥץưƤߤ褦 ϡΥץưȤ 1ܤΥѥ᡼ aaa , 2ܤΥѥ᡼ bbb ͿȤˤʤ롥 ȡΤ褦ʽϤϤ

 "The 1st parameter is "
 "aaa"
 "The 2nd parameter is "
 "bbb"

򸫤ȡץ¦ aaa bbb Ƥ뤳Ȥ狼롥
warning.png ruby Ǥ " (֥륯ơ)ǰϤäʬ ʸ Ǥ.



ARGV ʸ󰷤ˤѴʤȤ͡


η򸫤Ȥ狼뤬

ruby Ǥ ARGV[0], ... ʸȤư롥

顤ǡȤͿȤϡץѴɬפ롥 ץ򸫤褦

Ϳѥ᡼3Ĥ­ץ

  1. include Math
  2.  
  3. a = ARGV[0].to_i
  4. b = ARGV[1].to_i
  5. c = ARGV[2].to_i
  6.  
  7. p a+b+c

sample.rb Ȥ̾Ȳꤷơ

ruby -w sample.rb 3 8 2

ȥץưƤߤȡ 13 Ϥ


warning.png ΥץΡ.to_i ȤΤϡѿѴ뵡ǽ
warning.png Ʊͤˡ.to_f Ȥȼ¿Ѵ롥

Τ褦ˡ



ä ARGV[0], ... ΤĤʤ .to_i
¿ΤĤʤ .to_f ĤѴƤ.




ȤͿ줿(1)ȽꤷƽϤץ񤤤ư Υץե̾ sample.rb ȤʤС㤨

ruby -w sample.rb 11

ưȡ

 11
 "is odd."

ʤɤȽϤ褦ˤ褦ȤȤ



ARGV Ĥ뤫 ARGV.size ʬ


ʿͤ᤿ʤɡͿѥ᡼οޤäƤʤ礬롥 Ȥϡäѥ᡼θĿ򤽤ξΤ뤳Ȥн褹롥

Ūˤϡ

ARGV.size ǥѥ᡼θĿ狼.

㤨С

  1. include Math
  2.  
  3. p ARGV.size

Ȥ

ruby -w sample.rb a b c

ȤƥץưƤߤȡ3 ȤϤϤ




ѥ᡼ȤͿʣοʿѤϤץ񤳤 Ūˤϡ㤨С

ruby -w sample.rb 3 23 4 8 9

Ȥ

 9.4

ȽϤ褦ˤ褦ȤȤǤ롥

warning.png νϤ 9 ˤʤäƤޤͤϤɤΤǡֲƤΤפ褯ͤ褦
warning.png ͿΤ褦5ĤȤϸ¤ʤ6ĤǤ3ĤǤ100ĤǤ⡩ פʤ褦˥ץष褦



Ruby: (output)


ĥȥץåȤˤĤƤؤǤ


ʽϤ: print ̿

ޤǽϤϴñ p ̿ΤߤǹԤäƤܤƤʤΤɤߤˤ. ǡ⤦ɤߤ䤹 print ̿ˤĤƳؤܤ

Ȥϴñǡ

print() ˽ϤΤ򥫥ޤǶڤä¤٤

Ǥäɤߤ䤹ɽ롥

warning.png \n ȤüʸϤȤϤԤʤ 顤

ϤԤȤ print ̿ʸ \n 褦

ʲΥץ򸫤Ƥߤ褦

  1. include Math
  2.  
  3. a = 3.0
  4. b = 8.0
  5.  
  6. print("a is ",a," and b is ",b,".\n")
  7. print("Average is ", (a+b)/2, ".\n")

Υץưȡ

 a is 3.0 and b is 8.0.
 Average is 5.5.

ȤʤϤǤ롥
warning.png \ ȤϡˤäƤ ɽΤդ褦ƱΤ


ʤߤˡΥץ

  1. include Math
  2.  
  3. a = 3.0
  4. b = 8.0
  5.  
  6. print("a is ")
  7. print(a)
  8. print(" and b is ")
  9. print(b)
  10. print(".")
  11. print("\n")
  12.  
  13. print("Average is ")
  14. print((a+b)/2)
  15. print(".")
  16. print("\n")

Ƚ񤤤ƤƱϤˤʤ롥 Ȥ狼ˤΤ褦 print ̿ʬ䤷ץष䤹Ȥ⤢롥


notes.png ½: DzɤֵưͿѥ᡼ʿѤץפprint ̿ȤäƤ˲ɤơϤɤߤ䤹褦 Ūˤϡ㤨С

ruby -w sample.rb 3 23 4 8 9

Ȥ

 Input: 3.0 23.0 4.0 8.0 9.0
 Average: 9.4

ʤɤȽϤ褦ˤǤФ֤褤



ϤȤäƤˡ: ѥ & tee


̤ؤνϤϤ츫ʤʤäƤޤ ե˽ϤץεǽʤɤˤĤƤϸdzؤ֤ΤǡǤ ưˤäȹפ ̤ȥեƱ˽Ϥñ ˡˤĤƳؤܤ

ϴñǡ

ץεư
| tee ̤ؤνϤϿƤե̾
ǸˤäĤ

Ǥ褤

򸫤Ƥߤ褦㤨С

ruby -w sample.rb 3 23 4 8 9

Ȥ

 Input: 3.0 23.0 4.0 8.0 9.0
 Average: 9.4

ȽϤץФơoutput.dat Ȥ̾Υե˷̤ϿƤȤ롥

ξϡ

ruby -w sample.rb 3 23 4 8 9 | tee output.dat

Ȥǡ̤ˤ⡤output.dat Ȥեˤ

 Input: 3.0 23.0 4.0 8.0 9.0
 Average: 9.4

Ȥ̤Ϥ롥

warning.png ʤߤˡ | tee -a ե̾ Ȥ -a ĤƻȤȡեȤ˽ϤɲáפƤ롥 ˻Ȥʬ褦

ž夲

ޤǤ˳ؤμȤäơΤ褦ʥץꡤ̤ output.dat Ȥ̾Υե˵Ͽ褦 ΥץȤϡξΤǤ롥

  1. ư˥ѥ᡼Ȥ n Ϳ(礭 100 ٤ꤷ褦).
  2. 2 n-1 Τ٤ƤޤǤǡn ڤ뤫ɤϤ롥
  3. η̤Ѥơn ǿɤϤ롥

Ūˤϡsample.rb ȤץեȤơ㤨

ruby -w sample.rb 11

ưȡ

 11 is NOT divisable by 2.
 11 is NOT divisable by 3.
 11 is NOT divisable by 4.
 11 is NOT divisable by 5.
 11 is NOT divisable by 6.
 11 is NOT divisable by 7.
 11 is NOT divisable by 8.
 11 is NOT divisable by 9.
 11 is NOT divisable by 10.
 
 Answer: 11 is a prime number.

ȤϤ,

ruby -w sample.rb 12

ưȡ

 12 is divisable by 2.
 12 is divisable by 3.
 12 is divisable by 4.
 12 is NOT divisable by 5.
 12 is divisable by 6.
 12 is NOT divisable by 7.
 12 is NOT divisable by 8.
 12 is NOT divisable by 9.
 12 is NOT divisable by 10.
 12 is NOT divisable by 11.
 
 Answer: 12 is NOT a prime number.

ȤϤ褦ˤȤȤǤ롥

ơνϷ̤(n 100οˤͿ) output.dat Ȥե˵ϿƤȤȤˤʤ롥

warning.png ñĴʷ֤ǿʹ֤Ȥʤȿɤ׷׻ԥ塼դȤȤ褯̣浪



ݡ

ʲβˤĤơ긭Ĵȹͻȼ¹Ԥ򤷡

ExpMath1-Report-10

Ȥ̾Ĥ e-mail ˤƶ˥ݡȤȤФ补ʤƼ

  1. °(ز)
  2. ֹ
  3. ǯ
  4. ̾

񤯤Τ˺ʤ褦.

warning.png ʬΥݡȺġ륻åȤ򵭺ܤ(󡤺ΥݡȤ⤽Υġ륻åȤȤäƺ뤳)

ݡȲ

  1. ½ǽФƤФƤΡʬβץȡη̤򼨤
  2. 1. Υץ־ܺ٤ˡײ⤻补

about Icons, ClipArts

For details, see JNorth_arrow-right-sm.png this.