2019年2月18日 星期一

Julia 語言 --將輸入N個數字並加總後印出結果 for ...end

Online julia interpreter

https://www.tutorialspoint.com/execute_julia_online.php


println("請輸入N個數字並加總後印出結果")
print("請輸入N ==> ")
N = parse( UInt8,readline())

println()
innum = zeros(1,N)
result = 0.0
for j in 1:1:N
    print("請輸入第",j,"個數字")
    innum[j] =  parse( Float32,readline())
    println()
    s=innum[j]
    result = result + s
end

#using Printf
s = @sprintf("加總後 = %3.1f " , float(result) )
println(s)

輸入資料 STDIN  + 輸出結果 Result

5
12
13
43
23
29
$julia main.jl
請輸入N個數字並加總後印出結果
請輸入N ==> 
請輸入第1個數字
請輸入第2個數字
請輸入第3個數字
請輸入第4個數字
請輸入第5個數字
加總後 = 120.0 





沒有留言:

張貼留言

  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...