0% found this document useful (0 votes)
153 views4 pages

Solution LARP Lab 01

1. The document contains 15 programming problems involving basic mathematical operations, conditional statements, loops and functions in LARP. The problems include summing and averaging numbers, finding quotients, roots, whether a number is divisible, generating random numbers, comparing numbers, and counting/summing even and odd numbers.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views4 pages

Solution LARP Lab 01

1. The document contains 15 programming problems involving basic mathematical operations, conditional statements, loops and functions in LARP. The problems include summing and averaging numbers, finding quotients, roots, whether a number is divisible, generating random numbers, comparing numbers, and counting/summing even and odd numbers.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Solution Practice LARP 01

1. Input 2 numbers, find their sum, difference & product


read a
read b
write "Sum:", a+b
write "Difference:", a-b
write "Product:", a*b
2. Input 2 numbers. Perform & display result of complete division using “/” and result of integer division
using “//” operators
read a
read b
write "Complete Division:", a/b
write "Integer Division:", a//b
3. Input 3 numbers, calculate their average
read a
read b
read c
sum = a + b + c
write "Average:", sum/3
4. Input 3 numbers and find quadratic roots
read a
read b
read c
disc = b *b – 4 * a * c
disc = squareroot ( disc )
div = 2 * a
x1 = ( -b + disc ) / div
x2 = ( -b - disc ) / div
write "First Root:", x1
write "Second Root:", x2
--------------------------- Same program with check---------------------------
disc = b *b – 4 * a * c
if disc<0 then
write "Roots are Imaginary"
else
disc = squareroot ( disc )
div = 2 * a
x1 = ( -b + disc ) / div
x2 = ( -b - disc ) / div
write "First Root:", x1
write "Second Root:", x2
endif
5. Input angle from user and print sine using "sinus" function
Enter input angle 30, you will see result -0.988 instead of 0.5. This is because function take angle in
radians. However, you may value in degree by using formula angle*PI/180, where PI is a constant
defined in LARP and many languages. Use this formula and try with same input, this time answer
should be 0.5. Similarly, you can check different other angles like 0, 45, 60, 90

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

for i=1 to 10 step 1 do


n = random ( 1 , 100 )
write n
endfor
13. Repeat previous problem & count odd & even generated numbers

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

You might also like