ICT/2022/139
R.S.R. Ranathunga
Tutorial 03
1) Swap two values stored in two different variables.
1. What output do you need to generate? Display A and B swapped value
2. What input do you have/ need? Input Number 1 as A Input number 2 as B
3. What form will it be in? Integer value of Number 1 Integer value of Number 2
4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No
5. What are the other major tasks of the program?
- Input A
- Input B Declare “C” as Integer
- Assign A to C
- Assign B to A
- Assign C to B
- Display A, B
2) Check whether an entered number is negative, positive.
1. What output do you need to generate? Display message status of an entered number
2. What input do you have/ need? A number as x
3. What form will it be in? Numerical value
4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No
5. What are the other major tasks of the program?
Input x
X > 0
Yes: Display “Positive”
No: x==0
Yes: Display “Zero”
No: Display “Negative”
3) Check whether an entered year is leap year or not.
1. What output do you need to generate? An entered year is leap year or not
2. What input do you have/ need? Year as Y
3. What form will it be in? Integer value
4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No
5. What are the other major tasks of the program?
Input Y
Calculate Y % 4 == 0
Yes: Display “Leap year”
No: Display “ Not leap year ”
4) Write a task list that asks the user to type in two integer values at the terminal. Test these two numbers to determine if the first is evenly divisible by the second, and then display an appropriate message at the terminal. (Test for division by 0)
1. What output do you need to generate? A message about the status of division
2. What input do you have/ need? Number 1 as X Number 2 as Y
3. What form will it be in? Number 1 as a Integer value Number 2 as a integer value
4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No
5. What are the other major tasks of the program?
Input X
Input Y
Y==0
Yes: Display “Cannot divide”
No: (X % Y) == 0
Yes: Display “ Divisible “
No: Display “ Not divisible“
Comments
Post a Comment