Bài toán: Hãy tìm giá trị đầu tiên trong mảng một chiều các số nguyên có chữ số đầu tiên là chữ số lẻ. Nếu trong mảng không tồn tại giá trị như vậy thì hàm sẽ trả về giá trị 0 Ví dụ: Input 21 13 53 26 Output Gia tri thoa man bai […]
#bài tập c++
Thuật toán tìm số nguyên tố lớn nhất trong mảng một chiều bằng C++
Bài toán: Hãy tìm “số nguyên tố lớn nhất” trong mảng một chiều các số nguyên. Nếu mảng không có số nguyên tố thì trả về giá trị 0. Ví dụ: Input 1 3 4 5 6 11 21 Output So nguyen to lon nhat trong mang la: 11 Input 1 4 6 9 12 Output […]
Thuật toán tìm số chẵn lớn nhất nhỏ hơn mọi giá trị lẻ có trong mảng
Bài toán: Cho mảng một chiều các số nguyên. Hãy viết hàm tìm số chẵn lớn nhất nhỏ hơn mọi giá trị lẻ có trong mảng. Nếu mảng không tồn tại số lẻ nào thì in ra số -1. Ví dụ: Input: 3 4 5 6 7 9 8 Output: So chan lon nhat nho hon […]
Tìm chữ số xuất hiện ít nhất trong một mảng bằng C++
Bài toán: Cho mảng một chiều các số nguyên. Hãy viết hàm tìm chữ số xuất hiện ít nhất trong mảng đã cho. Trong trường hợp có hai hay nhiều chữ số có số lần xuất hiện bằng nhau thì in ra chữ số nhỏ nhất. Ví dụ: Input: 1 12 13 23 51 Output: […]
Tạo dãy số ngẫu nhiên không trùng trong C/C++
Làm sao để tạo dãy số ngẫu nhiên không trùng nhau trong C/C++? Hãy cùng Nguyễn Văn Hiếu đi giải quyết bài toán sinh số ngẫu nhiên không trùng trong bài viết này nhé. Mình sẽ hướng dẫn các bạn hai cách khác nhau để tạo dãy số ngẫu nhiên không trùng lặp. Bắt đầu […]