0% found this document useful (0 votes)
162 views2 pages

Solution LARP Lab 02

This document contains 6 programming problems of increasing difficulty that involve using loops to iterate through ranges of numbers and perform calculations on them. The problems include summing ranges of numbers, counting numbers divisible by given values, and outputting even and odd numbers in ranges. Loops (for loops), conditional statements (if/else), arithmetic operators, and string concatenation are used to solve the problems.

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)
162 views2 pages

Solution LARP Lab 02

This document contains 6 programming problems of increasing difficulty that involve using loops to iterate through ranges of numbers and perform calculations on them. The problems include summing ranges of numbers, counting numbers divisible by given values, and outputting even and odd numbers in ranges. Loops (for loops), conditional statements (if/else), arithmetic operators, and string concatenation are used to solve the problems.

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/ 2

Solution Practice LARP 02

Note: Problems difficulty level is gradually increasing. If any problem seems very easy or you have already
did it in LARP, move to next problem:
1. Input 2 numbers and print numbers between them
read n1
read n2
for i=n1 to n2 step 1 do
write i
endfor
2. Input n (number). Print all numbers divisible by n from 50 to 200
read n
for i=50 to 200 step 1 do
if i%n=0 then
write i
endif
endfor

3. Compute and print sum of numbers from 50 to 100


sum=0
for i=50 to 100 step 1 do
sum=sum+i
endfor
write "Sum of numbers from 50-100 is:", sum

4. Compute and print sum of 50 to 100 odd numbers & even numbers and print them
sumO=0
sumE=0
for i=50 to 100 step 1 do
if i%2=0 then
sumE=sumE+i
else
sumO=sumO+i
endif
endfor
write "Sum of even numbers from 50-100 is:", sumE
write "Sum of odd numbers from 50-100 is:", sumO

Run following program before next question:


s=""
for i=1 to 100 step 1 do
s=s+tostring(i)+" "
endfor
write s
5. Print 1-100 even numbers and 1-100 odd number in single line each, using single loop.
Hint: Use previous program
sOdd=""
sEven=""
for i=1 to 100 step 1 do
if i%2=0 then
sEven = sEven + tostring(i) + " "
else
sOdd = sOdd + tostring(i) + " "
endif
endfor
write "Even Numbers:", sEven
write "Odd Numbers:", sOdd
6. Run a loop from 1 to 100 and count numbers divisible by 3, 5 and 7. After the loop, print all counts
count3=0
count5=0
count7=0
for i=1 to 100 step 1 do
if i%3=0 then
count3 = count3 + 1
endif
if i%5=0 then
count5 = count5 + 1
endif
if i%7=0 then
count7 = count7 + 1
endif
endfor
write "Count of numbers divisible by 3 is:", count3
write "Count of numbers divisible by 5 is:", count5
write "Count of numbers divisible by 7 is:", count7

You might also like