WHILE
Bài 1: Declare a variable which has the age of the person. Print the user’s name as many times as his age.
 |
My Code + result
Bài 2: The program displays even numbers from 1 to 30.
|
 |
My Code + result |
Bài 3: The program displays numbers from 10 to 0 in the reverse order.
 |
My Code + result |
Bài 4: The program will accept integers and display them until zero (0) is entered.
 |
My Code + result |
Bài 5: Find the factorial of a number.
Hint:
-
To begin, set the factorial of the number to be one.
While the number is greater than one
Set the factorial to be the factorial multiplied by the number.
-
-
 |
My Code + result |
Bài 6: Write a program to print the series 100, 95 , 90, 85,………., 5.
 |
My Code + result |
Bài 7: Accept two numbers num1 and num2. Find the sum of all odd numbers between the two numbers entered .
Bài 8: Write a program to generate the Fibonacci series. (1,1,2,3,5,8,13,………)
 |
My Code + result |
Bài học rút ra:
- Cấu trúc: do { statements; } while (condition;).
- Thay vì viết a = a + b ta có thể viết a += b .
- Thay vì viết a = a - 1 hay a = a + 1 ta có thể viết a-- hay a++ để giảm hay tăng lên 1 đơn vị .
No comments:
Post a Comment