-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab6b4.c
More file actions
41 lines (33 loc) · 740 Bytes
/
lab6b4.c
File metadata and controls
41 lines (33 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
int isPrime(int num) {
if (num <= 1) {
return 0;
}
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return 0;
}
}
return 1;
}
int main() {
int arr[5];
int count = 0;
printf("Nhap 5 so nguyen to:\n");
while (count < 5) {
int num;
printf("nhap so thu %d: ", count + 1);
scanf("%d", &num);
if (isPrime(num)) {
arr[count] = num;
count++;
} else {
printf("So ban nhap khong phai so nguyen to. Hay nhap lai.\n");
}
}
printf("Cac so nguyen to da nhap:\n");
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
return 0;
}