Solution LARP Lab 01
Solution LARP Lab 01
read angle
write sinus ( angle )
-----------------------------------
read angle
deg = angle * PI / 180
write sinus ( deg )
6. Input word from user and print in uppercase & lowercase using functions: uppercase, lowercase
query "Enter any word:", w
write "Upper case:", uppercase(w)
write "Upper case:", lowercase(w)
7. Input two numbers and find whether first number is divisible by second number or not?
Hint: Use % operator to find remainder
read a
read b
if a % b = 0 then
write "First number is divisible by second"
else
write "First number is not divisible by second"
endif
8. Calculate pay of an employee based on the hours worked. The input includes the employee total
hours worked this week and their hourly pay rate. The employee is to be paid their basic wage for the
first 40 hours worked and time-and-a-half (i.e. 50% more) for all hours above 40 (overtime pay). Output
the regular pay, overtime pay, and total pay for the week on the screen. If the employee worked 40 hours
or less, do not output any information about overtime pay. For further understanding, see example:
Hours Worked: 30 Hours Worked: 50
Hourly Pay Rate: 200 Hourly Pay Rate: 220
Regular pay 6000 Regular pay 8800
------------------------------------- Overtime 1100
Total 6000 -------------------------------------
------------------------------------- Total 9900
-------------------------------------
Normal rate is 220 but overtime rate is 330 that is 220+110
query "Hours Worked:", hours
query "Hourly Pay Rate:", rate
amount = hours * rate
write "Regular pay ", amount
if hours>40 then
overtime = (hours - 40) * (rate * 0.5)
write "Overtime ", overtime
amount = amount + overtime
endif
write "---------------------------"
write "Total ", amount
write "---------------------------"
9. Take two numbers from the user and determine the larger number.
read a
read b
if a>b then
write "First is larger"
else
write "Second is larger"
endif
10. Input two numbers, say n1, & n2. Print numbers between n1 & n2 including both n1 & n2.
read n1
read n2
for i=n1 to n2 step 1 do
write i
endfor
11. Repeat previous problem, if n1 is smaller than n2, print numbers from n1 to n2, otherwise print
numbers between n2 & n1.
read n1
read n2
if n1<n2 then
for i=n1 to n2 step 1 do
write i
endfor
else
for i=n2 to n1 step 1 do
write i
endfor
endif
12. Generate & print 10 random numbers in range 1-100, using function random(1,100). Use different
variables to control loop and for storage of random number, if you store, otherwise you may use
write statement with random function to print random values directly
countO=0
countE=0
for i=1 to 10 step 1 do
n = random ( 1 , 100 )
if n%2=0 then
countE = countE+i
else
countO = countO +i
endif
endfor
write "Count of even numbers:", countE
write "Count of odd numbers:", countO
14. Run loop 10 times take input from user inside loop. Again count even & odd numbers. Print count
after end of loop
countO=0
countE=0
for i=1 to 10 step 1 do
read n
if n%2=0 then
countE = countE+i
else
countO = countO +i
endif
endfor
write "Count of even numbers:", countE
write "Count of odd numbers:", countO
15. Run loop 10 times take input from user inside loop. Sum even numbers & odd numbers separately.
Outside loop check & print whether sum of even numbers is greater or sum of odd numbers is
greater
sumO=0
sumE=0
for i=1 to 10 step 1 do
if i%2=0 then
sumE=sumE+i
else
sumO=sumO+i
endif
endfor
if sumE>sumO then
write "Sum of even numbers is greater than sum of odd numbers"
else
write "Sum of odd numbers is greater than sum of even numbers"
endif