JuliaLab Exp3&4
JuliaLab Exp3&4
3. a. Develop a Julia program to request a score in a test and print a letter grade based on the
following:
F: score < 50 B:50<=score<75 A: score >= 75
PROGRAM:
OUTPUT:
Enter the score in test
stdin> 67
Grade obtained is B
3. b. Develop a Julia Program for Given three integer values representing the sides of a
triangle, print:
• Not a triangle: if the values cannot be the sides of any triangle. This is so if any value is
negative or zero, or if the length of any side is greater than or equal to the sum of the other
two.
• Scalene: if the triangle is scalene (all sides different)
• Right angled: if the triangle is right-angled
• Isosceles: if the triangle is isosceles (two sides equal)
• Equilateral: if the triangle is equilateral (three sides equal).
PROGRAM:
OUTPUT:
Isosceles
4. a. An amount of money P (for principal) is put into an account which earns interest at r%
per annum. So, at the end of one year, the amount becomes P + P×r/100. This becomes the
principal for the next year. Develop a Julia program to print the amount at the end of each
year for the next 10 years. However, if the amount ever exceeds 2P, stop any further printing.
Your program should prompt for the values of P and r.
PROGRAM:
function calculatePay()
print("Hours worked? ")
hours = parse(Float64, readline())
print("Rate of pay? ")
rate = parse(Float64, readline())
if hours <= 40
regPay = hours * rate
ovtPay = 0
else
regPay = 40 * rate
ovtPay = (hours - 40) * rate * 1.5
end
grossPay = regPay + ovtPay
println("\nRegular pay: ", regPay)
println("Overtime pay: ", ovtPay)
println("Gross pay: ", grossPay)
end # calculatePay
calculatePay()
OUTPUT:
Hours worked?
stdin> 45
Rate of pay?
stdin> 5.5
4. b. Develop a Julia program which reads numbers from a le (input.txt) and nds the largest
number, smallest number, count, sum and average of numbers.
PROGRAM:
# To access and display le elements
function inputlist()
println("List of input numbers")
for num in eachline("input.txt")
num = parse(Int, num)
println(num)
end
end
# Regular ow of program
# Function calls
inputlist()
minimum()
maximum()
count()
sum()
average()
OUTPUT:
Minimum element is 10
Maximum element is 89
Total number of elements in file= 10
Sum of all numbers= 377
Average of all numbers= 37.7