0% found this document useful (0 votes)
34 views

Lab 2

The document describes 9 lab exercises involving writing computer algorithms to: 1) Compare two people's ages and display if they are the same or different. 2) Get a year from the user and display how many years have passed since 1900. 3) Get a number from the user and display if it is odd or even. 4) Calculate and display the sum of all even numbers between 5 and 105. 5) Display all odd numbers between 10 and 100. 6) Display the squares and cubes of numbers from 1 to a given number. 7) Display a Fahrenheit to Celsius conversion table from 20F to 100F in 5 degree steps. 8) Calculate the product of numbers

Uploaded by

Libyan Knight
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Lab 2

The document describes 9 lab exercises involving writing computer algorithms to: 1) Compare two people's ages and display if they are the same or different. 2) Get a year from the user and display how many years have passed since 1900. 3) Get a number from the user and display if it is odd or even. 4) Calculate and display the sum of all even numbers between 5 and 105. 5) Display all odd numbers between 10 and 100. 6) Display the squares and cubes of numbers from 1 to a given number. 7) Display a Fahrenheit to Celsius conversion table from 20F to 100F in 5 degree steps. 8) Calculate the product of numbers

Uploaded by

Libyan Knight
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab Exercises

Lab 2
1. Get the age of two different people and compare if their ages are the same or not, if it
is the same, display “They are at the same age”. If not, display “Ages are different”.

2. Draw the flowchart that gets a year from user and display how many years passed
since 1900. If the given input is less than 1900 display “you are ancient!”.

3. Get a whole number from user, if it is an odd number, display it. If it is an even
number divide the number to 2 and display the result. Hint: if (x mod 2) equals to 0
then the number is even.

4. Create a computer algorithm that calculates and displays the sum of all even whole
numbers between 5 and 105.

5. Create a computer algorithm that displays all odd whole numbers between 10 and 100

6. Create a computer algorithm to find squares and cubes of a specific number starting
from 1 up to that number. The algorithm will ask the user to enter the whole number.
The algorithm will then show the square and cube of all the numbers up to that
number (including the number itself).
EXAMPLE:
INPUT NUMBER: 3
Number Square Cube
1 1 1
2 4 8
3 9 27

7. Create a computer algorithm that displays a conversion table for degrees Fahrenheit to
degrees Celsius beginning with 20oF through 100oF in steps of 5oF. The conversion
formula is given below: Celsius = 5(Fahrenheit – 32) / 9
EXAMPLE:
20F -6C
25F -5C
8. Create a computer algorithm that would calculate the result of the following formula:
90

∏𝑋
𝑥=10
9. Create a computer algorithm that would get the number n from the user and calculate
the result of the following formula below:
1000

∑ 𝑋𝑛
𝑥=!

You might also like