up
This commit is contained in:
36
bai_tap_dem_so.js
Normal file
36
bai_tap_dem_so.js
Normal file
@@ -0,0 +1,36 @@
|
||||
// Bài 1: Viết chương trình khởi tạo nhập vào một mảng số nguyên gồm 10 phần tử.
|
||||
// Chương trình thực hiện tính và hiển thị xem có bao nhiêu số nguyên lớn hơn hoặc bằng 10.
|
||||
|
||||
let count = 10;
|
||||
let soNguyenList = []
|
||||
|
||||
// 1 2 3 4 5 6 7 8 9 10 => 1
|
||||
// 1 20 3 4 50 6 7 8 9 10 => 3
|
||||
let demKq = 0;
|
||||
|
||||
for(let i = 0; i < count; i++) {
|
||||
let soNguoiDungNhap = +prompt("Nhập số nguyên thứ " + (i + 1));
|
||||
|
||||
while(true) {
|
||||
if (isNaN(soNguoiDungNhap)) {
|
||||
alert("phải nhập số")
|
||||
soNguoiDungNhap = +prompt("Nhập số nguyên thứ " + (i + 1));
|
||||
}else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
soNguyenList[i] = soNguoiDungNhap;
|
||||
if(soNguyenList[i] >= 10) {
|
||||
demKq = demKq + 1;
|
||||
}
|
||||
}
|
||||
|
||||
console.log("soNguyenList", soNguyenList)
|
||||
|
||||
console.log("số nguyên lớn hơn or bằng 10 trong danh sách là ", demKq)
|
||||
|
||||
|
||||
// do {
|
||||
|
||||
// }while(true);
|
||||
Reference in New Issue
Block a user