読者です 読者をやめる 読者になる 読者になる

個人的自由ノート

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

問題を解く

print "x : "
x = gets.chomp.to_f
puts "x = #{x}"



b1 = true
b2 = false

puts "b1 = #{b1}"
puts "b2 = #{b2}"




# coding: utf-8
print "xの値 : "
x = gets.chomp.to_i
print "yの値 : "
y = gets.chomp.to_i
print "zの値 : "
z = gets.chomp.to_i

puts sprintf("%.3f", (x + y + z) / 3)




# coding: utf-8
print "xの値 : "
x = gets.chomp.to_i
print "yの値 : "
y = gets.chomp.to_i
print "zの値 : "
z = gets.chomp.to_i

ave = (x + y + z).to_f / 3

puts sprintf("%.3f", ave)




a = 10.0.to_i
a = 10.0

puts a




puts sprintf("  float \t  int")
puts sprintf("-------------------------")
x = 0.0
i = 0

while i <= 1000 do
  puts sprintf("%9.7f\t%9.7f", x, i)
  i += 1
  x += 0.001
end
import java.util.Scanner;

class q6_7 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("人数 : ");
        int n = scan.nextInt();
        int[] point = new int[n];
        int max,min = 0;
        int sum = 0;
        for(int i = 0; i < n; i++) {
            System.out.print(i + "番の点数 : ");
            point[i] = scan.nextInt();
            sum += point[i];
        }
        max = point[0];
        min = point[0];
        for(int j = 0; j < n; j++) {
            if(max < point[j]) {
                max = point[j];
            }
            if(min > point[j]) {
                min = point[j];
            }
        }
        System.out.println("合計点は" + sum + "です。");
        System.out.println("平均点は" + (double)sum / n + "です。");
        System.out.println("最高点は" + max + "です。");
        System.out.println("最低点は" + min + "です。");
    }
}




import java.util.Scanner;

class q6_8 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("要素数 : ");
        int n = scan.nextInt();
        int[] a = new int[n];
        int answer = 0;
        for(int i = 0; i < n; i++) {
            System.out.print("a[" + i + "] = ");
            a[i] = scan.nextInt();
        }
        System.out.print("探す数値 : ");
        int target = scan.nextInt();
        for(int j = 0; j < n; j++) {
            if(a[j] == target) {
                answer = j;
                break;
            }
        }
        System.out.println("それはa[" + answer + "]にあります。");
    }
}
open Printf;;
print_string "変数a : ";;
let a = read_int();;
print_string "変数b : ";;
let b = read_int();;
print_string "変数c : ";;
let c = read_int();;

print_endline "a <= b <= cとなるようにソートしました。";;

let target = [a; b; c];;
let answer = List.sort (fun x y -> compare x y) target;;

List.iter (printf "%d\n") answer;;



Random.self_init();;
let a = Random.int 3 in if a == 0 then print_endline "グー"
                        else if a == 1 then print_endline "チョキ"
                        else if a == 2 then print_endline "パー";;




print_string "何月ですか : ";;
let month = read_int();;

let answer = if month >= 3 && month <= 5 then "春です。"
             else if month >= 6 && month <= 8 then "夏です。"
             else if month >= 9 && month <= 11 then "秋です。"
             else "冬です。";;

print_endline answer;;




let flag = ref false in
    while not !flag do
      print_string "整数値 : ";
      let n = read_int() in
      let answer = if n > 0 then "その値は正です。"
                   else if n < 0 then "その値は負です。"
                   else "その値は0です。" in
      print_endline answer;
      print_string "もう一度? 1...Yes/0...No : ";
      let tmp = read_int() in
      if tmp == 0 then flag := true
    done;;