Ȼ/03

Top / Ȼ / 03

ץߥ I

ޤϡ˺Ǿ¤Ρץƥ˥μΤ.
㤨СѸؤ֤ˤäƥե٥åȤΤʤȻϤޤʤ褦ˡץߥ󥰤ˤɬפμΤ.

ѿ

ѿ

ɤȤѿפȤǰϥץǤȤơ.
㤨СʿѤץϡ(ΤˡԤֹĤɽƤ)

  1. include Math
  2.  
  3. a = [1.2, -3.0, 3.3, 4.1, 0.9]
  4.  
  5. sum = 0.0
  6. for i in 1..a.size do
  7.   sum += a[i-1]
  8.   end
  9.  
  10. average = sum / a.size
  11.  
  12. p average

ä

3: a
5: sum
6: i
10: average

ѿǤ.

warning.png Ruby Ǥѿ̾ʸǻϤüʰ(. ѹԲǽ)ˤʤ. ϽؼԤˤϴְ㤤ΤȤȤʤΤǡ

ѿ̾ϾʸǻϤ٤.


ޤѤäȽ񤯤ȡԥ塼ȳ(Ⱦʬʾ)Ǥϡ

a = b ǤϤʤa b Ȥ̿Ǥ.

warning.png ְ㤨䤹Τդ褦. ʤߤˤΰ? ŪаޤˤΤǤ


Υץ

(3) a = ...
(5) sum = ...
(7) sum += ... ֱդ­ü
(10) average = ...

˳.

§黻¾δñʱ黻

ñʷ׻ˤĤƤϡۤܿؤ̤˻Ȥ뤬ˤϴƤɬפ. ʲñ褦.

ˡ
warning.png ط׻,ʤɤΤĤϡRuby ϤΤޤޤǤϹԤʤΤǡ

ץκǽ include Math ȤԤ򤤤ĤƤ.

ϡֿط׻򤹤ץɤ߹פȤ̣ȻפФ褤.


黻 ʰɽ

­+ Ȥ3.0 + 5.0 (= 8.0)
- Ȥ3.0 - 5.0 (= -2.0)
* Ȥ3.0 * 5.0 (= 15.0)
/ Ȥ3.0 / 5.0 (= 0.6) ¿񤯤ȼ¿ȤƷ׻
3 / 5 (= 0) 񤯤ȤƷ׻
;% Ȥ5 % 3 (= 2)
٤** Ȥ2**3 (= 8)
.abs Ĥ(-2).abs (= 2)
ͼθ.round Ĥ(1.6).round (= 2)
ڤ夲.ceil Ĥ(1.6).ceil (= 2)
ڤ겼.floor Ĥ(1.6).floor (= 1)
пlog ؿȤlog(10.0) (= 2.3025...) п
log10 ؿȤlog10(10.0) (= 1.0) 10п
ؿexp ؿȤexp(1.0) (= 2.71828...)
ʿsqrt ؿȤsqrt(2.0) (= 1.41421...)
Ѵؿsinؿ, cosؿ, tanؿ...sin(1.0) (= 0.84147...)
ջѴؿѴؿ̾κǽ a Ĥacos(0.54) (= 1.000...)
rand Ȥrand (= ?) 0ʾ1̤μ¿
?== ȤĴ٤Ȥʤɤ˻Ȥ. .
椬ΩĤ?>, <, >=, <= Ȥ
԰פ?!= Ȥ
A B&& ǤĤʤ(A) && (B)
A ⤷ B¦¦ (2)ǤĤʤ(A) ¦¦ (B)
A ! ƬˤĤ!(A)



ʰɽ

ͥԥ(e)E2.71828...
߼ΨPI3.14159...

ץΡήפ椷褦: §

ޤץδܤؤܤ.
줬 ؤ֥ץ縶§Ȥơ

§: ץϾ夫鲼ؤȼ¹Ԥ.

ȤΤ.
ȲؤʤΤǡΡήפѤ뤿ˡѰդƤ.
ˡˤĤơʲñʤΤؤܤ.

줿롼: ܤΥ롼פ狼 for ̿

ִñʡ줿롼פ롤Ȥؤܤ.
ˤϲफˡ뤬ޤϥ롼פȤ ܤΥ롼פfor ̿ؤܤ.

ʸˡ礶äѤˤϰʲ̤Ǥ. 㤨 5 롼פ


for i in 1..5 do
˽񤤤ʬ 5 ¹Ԥ
ξ硤ѿ i ˡֺ ܤΥ롼פפοäƤ
end


Ȥ.
ĤʬʬǹѤʬǤȻפФ褤.

notes.png for ̿Ȥäơ1 100 ޤǽ֤˿ܤ­Ƥץ񤤤Ƥߤ褦. ޤǤ­η̤ ̤˽Ф褦ˤƤߤ褦.


ξϡ㤨мΤ褦ʥץˤʤ(ΤˡԤֹĤɽƤ). ʬǽ褿.

  1. include Math
  2.  
  3. sum = 0
  4. for i in 1..100 do
  5.   sum += i
  6.   p sum
  7.   end

warning.png 3ܤ sum = 0 ϡֹפäƤϤѿ sum 򡤷׻ǰΰ٤ˤä󥼥ˤƤפȤư. ץबʣˤʤäƤȡǰΰ١פ뤫ʤǤޤưɤ礭ѤäƤΤǵĤ褦.

ˤäơưѤ if ̿

ˡˤäưѤ if Ȥ̿ؤܤ.
줬Ǥȡ֥ץ餷ץब(鿴Ԥʤ)񤱤.

ޤäѤʸˡŪʤΤ򼨤ȼΤ褦ˤʤ.


if () then
郎硤¹Ԥ
else
郎ʤ硤¹Ԥ
end


ĤʬʬǹѤʬǤȻפФ褤ΤϾƱǤ.


notes.png if ̿ȤäơŬȽǤƽϤץ񤤤Ƥߤ褦. ϥץκǽŬ˼ʬǷƤޤäƤ褤.


ξϡ㤨мΤ褦ʥץˤʤ(ΤˡԤֹĤɽƤ). ʬǽ褿.

  1. include Math
  2.  
  3. n = 5
  4. p n
  5.  
  6. if (n % 2 == 0) then
  7.     p "is even"
  8.   else
  9.     p "is odd"
  10. end

warning.png== ()򼨤Ǥ. Τ褦ˡؤȡֵλȤפۤʤ뤳ȤΤդ褦.

ž夲

notes.png for ̿ if ̿ȤäơŬǿɤȽǤƽϤץ񤤤Ƥߤ褦. 100 ʾ 300 ʲ餤ǡץκǽŬ˼ʬǷƤޤäƤ褤.

warning.png 䤳. ɤäǤ뤫ͤʤȤʤ.
ϡƤʤͤ

˥르ꥺ򤶤äȥǥ󤷤Ƥݤ.

(ޤǤ)Ūˤ᤯ijμ¤˥ץߥ󥰤Ǥ뤳Ȥʬ.

warning.png ץߥ󥰤˴Ƥʤͤϡä르ꥺˤ褦ȹͤʤ褤. оݿ礭櫓ǤϤʤΤǡǿ˴ŤƤҤ˥å򤵤Ф褤

warning.png ֺΤȤǿȻפ뤫ɤפȤȽͤѿƤʤɤιפ򤹤Ȥ褤. 㤨СisPrime Ȥѿäơǽ yes Ƥ. ơdzڤ줿 no . С

ݡ

ֵӹԤä½ˤĤơñˤޤȤ᤿򤻤.
ޤž夲ʬǼʬǽ񤤤ץ𤻤.

Ƽ

  1. °(ز)
  2. ֹ
  3. ǯ
  4. ̾
  5. οΥݡ(θȤˤĤƵŤ)

񤯤Τ˺ʤ褦.

about Icons, ClipArts

Some icons in this page are downloadable at ICONFINDER.

The "note" icon notes.png designed by Marco Martin is distributed with the LGPL licence,
the "warning" icon warning.png designed by Alexandre Moore with the GPL licence
and the "triangle" icon JNorth_arrow-right-sm.png designed by Joseph North is distributed with the Creative Commons (Attribution-Noncommercial-Share Alike 3.0 Unported) licence.

Some clip arts used in this page are downloadable at Open Clip Art Library.
We deeply appreciate their superb works. With licence, they describe that "the actual clipart content on open clipart library is Public domain" in the web.