
Liệt kê các số thuận nghịch chia hết cho k
- Posted by Thân Triệu
- Phân loại Bài tập C#, Bài tập lập trình C, Bài tập lập trình C++, Bài tập lập trình Java, Bài tập Python
- Date 24/08/2020
- Các bình luận 20 Các bình luận
Nội dung này chúng ta sẽ giải quyết vấn đề được đưa ra như sau: “Cho một số nguyên dương k được nhập vào từ bàn phím. Hãy viết chương trình tìm và in ra tất cả các số thuận nghịch có 8 chữ số thỏa mãn chia hết cho k”.
Để giải quyết bài này, trước hết ta cần kiểm tra xem liệu k có khác 0? Sau đó cần một hàm kiểm tra số thuận nghịch và hàm kiểm tra chia hết cho k hay không. Các bước thực hiện của thuật toán chính như sau:
- Cho i chạy từ 10000000 đến 99999999. Xét lần lượt từng phần tử.
- Nếu i là số thuận nghịch đồng thời chia hết cho k thì in ra i
- Ngược lại bỏ qua i
Thuật toán kiểm tra số thuận nghịch:
- Khởi tạo biến rev = 0; gán m = n;
- Lặp chừng nào m còn lớn hơn 0:
- rev = rev*10 + m%10;
- m /= 10;
- Kiểm tra và trả về rev == n
Thuật toán kiểm tra n chia hết cho k:
- Nếu n chia dư cho k == 0 thì ta nói n chia hết cho k
- Ngược lại n không chia hết cho k
Mã nguồn chương trình thực hiện trên các ngôn ngữ lập trình C, C++, Java, C#, Python:
C
C++
Java
C#
Python
Nếu bạn có bình luận gì đừng ngần ngại để lại phía dưới nhá.
Có thể bạn quan tâm

Kiểm tra số thuận nghịch
23 Tháng Tám, 2020

Tính tổng S = 1! + 2! + … + n!
22 Tháng Tám, 2020

Tính tổng cấp số cộng phân số
22 Tháng Tám, 2020
20 Comments
Thanks for sharing, this is a fantastic article. Really looking forward to read more. Ibbie Kean Abelard
I pay a quick visit every day some blogs and websites to read content, but this website gives feature based writing. Goldie Taddeo Alarise
What a stuff of un-ambiguity and preserveness of precious know-how regarding unpredicted emotions. Cristina Zak Sigmund
There is no way to quantify the immense popularity enjoyed by the sport of soccer in countries the world over. Rici Orren Cad
Well I really enjoyed studying it. This article offered by you is very constructive for correct planning. Celestyn Marco Soraya
Excellent article! We are linking to this particularly great article on our site. Keep up the good writing. Deeyn Kimball Orazio
thank you!
Site Rank Services offers affordable premium SEO packages & helps increase the visibility of your site in the search engines. We help you generate more profits Stanford Mehringer
This is my first time pay a visit at here and
i am really happy to read all at alone place.
I think this is a real great blog. Much obliged. Wendy Ferner
Wow, that’s what I was seeking for, what a information! existing here at this website, thanks
admin of this web site.
Great blog post.Much thanks again. Fantastic. Rufus Stribling
Im obliged for the blog. Reggie Maduena
Thanks so much for the blog post.Thanks Again. Great.
You’re welcome!
Woah! I’m really loving the template/theme of this blog.
It’s simple, yet effective. A lot of times it’s
very difficult to get that “perfect balance” between superb usability and visual appearance.
I must say you’ve done a superb job with this. Also, the blog loads extremely fast for me on Internet explorer.
Superb Blog!
I have been browsing on-line greater than 3 hours these days, but I by no means discovered any attention-grabbing article like yours.
It’s lovely price sufficient for me. In my view, if all website owners and bloggers made good content as you did,
the internet will be much more useful than ever before.
magnificent issues altogether, you just received a new reader.
What might you recommend about your submit that you made some days in the past?
Any positive?
Usless informations.. that i already knew.. my question is how to download to your gallary? Blondie Janet Beverley
This content was really awesome Thank you for creating it. Ondrea Norbie Sommers