Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "conio.h"
- int so_nguyen_to(int N);
- int main() {
- int N, i;
- do {
- printf("\n Nhap vao so N = ");
- scanf("%d", & N);
- }
- while (N <= 0);
- printf("\n Cac so nguyen to nho hon %d :", N);
- for (i = 2; i <= N; i++) {
- if (so_nguyen_to(i))
- printf(" %d ", i);
- }
- getch();
- }
- // Ham kiem tra so nguyen to
- int so_nguyen_to(int N) {
- int i;
- if (N == 2)
- return 1;
- else {
- for (i = 2; i < N; i++) {
- if (N % i == 0)
- return 0;
- }
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement