落書きノート

ふと自分が気になった事を書いてます

Rubyで問題を解く

# coding: utf-8
print "段数は : "
n = gets.chomp.to_i

for num in 1..n do
  for num2 in 1..num do
    print '*'
  end
  puts
end



# coding: utf-8
print "段数は : "
n = gets.chomp.to_i

for num in 1..n do
  for num2 in num..n do
    print '*'
  end
  puts
end




# coding: utf-8
print "段数は : "
n = gets.chomp.to_i

for num in 1..n do
  for num2 in num..n - 1 do
    print ' '
  end
  for num3 in 1..num do
    print '*'
  end
  puts
end




# coding: utf-8
print "段数は : "
n = gets.chomp.to_i

for num in 1..n do
  for num2 in 1..num - 1 do
    print ' '
  end
  for num3 in num..n do
    print '*'
  end
  puts
end




# coding: utf-8
print "段数は : "
n = gets.chomp.to_i

for num in 1..n do
  for num2 in num..n - 1 do
    print ' '
  end
  for num3 in 1..(num - 1) * 2 + 1 do
    print '*'
  end
  puts
end




# coding: utf-8
print "段数は : "
n = gets.chomp.to_i

for num in 1..n do
  for num2 in num..n - 1 do
    print ' '
  end
  for num3 in 1..(num - 1) * 2 + 1 do
    print num % 10
  end
  puts
end



# coding: utf-8
print "2以上の整数値 : "
n = gets.chomp.to_i
flag = true

for num in 2..n - 1 do
  flag = false if n % num == 0
end

if flag then
  puts "それは素数です。"
else
  puts "それは素数ではありません。"
end