0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaの算術・代入演算メニューの演習問題のRubyでの模範解答

Posted at

Paiza の算術・代入演算メニューの演習問題のRubyでの模範解答です。
簡単なので、いらないような気もしますが、ご参考までに。

STEP: 1 足し算
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__arithmetic_step1

step1.rb
n = 1231 + 5178

puts n

STEP: 2 引き算・掛け算
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__arithmetic_step2

step2.rb
a,b = gets.split(' ').map(&:to_i)
d = a - b
p = a * b

puts "#{d} #{p}"

STEP: 3 割り算
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__arithmetic_step3

step3.rb
a = 437326
b = 9085
x = a / b
y = a % b

puts "#{x} #{y}"

STEP: 4 掛け算 2
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__arithmetic_step4

step4.rb
a,b,c = gets.split(' ').map(&:to_i)
x = a * a
y = b * b + c * c

puts "#{x} #{y}"

STEP: 5 累乗
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__arithmetic_step5

step5.rb
a = 202
b = 134
c = 107

n = ((a + b) * c) ** 2

puts n

STEP: 6 累乗 2
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__arithmetic_step6

step6.rb
a,b,c,d = gets.split(' ').map(&:to_i)

n = ((a + b) * c) ** 2 % d

puts n

STEP: 7 代入演算 1
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__substitution_step1

step7.rb
n = 0
n = n + 3286
n = n * 4736
n = n % 12312

puts n

STEP: 8 代入演算 2
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__substitution_step2

step8.rb
n = 0
a,b,c = gets.split(' ').map(&:to_i)
n = n + a
n = n * b
n = n % c

puts n

STEP: 9 代入演算 3
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__substitution_step3

step9.rb
n = 10000
n = n / 361
n = n % 28

puts n 

STEP:10 代入演算 4
https://paiza.jp/works/mondai/arithmetic_substitution_op/arithmetic_substitution_op__substitution_step4

step10.rb
a,b = gets.split(' ').map(&:to_i)
n = 10000
n = n / a 
n = n % b

puts n 
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?