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 





沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...