BUPT-homework/semester1/pset4/4-primes.c

40 lines
610 B
C

#include <stdio.h>
// Function prototypes
void get_primes(void);
int is_prime(int num);
int main(void) {
// Initialize variables
int lines;
scanf("%d", &lines);
for (int i = 0; i < lines; i++) {
get_primes();
}
return 0;
}
void get_primes(void) {
int temp; // Temporary
int count = 0;
scanf("%d", &temp);
while (temp != -1) {
if (is_prime(temp) == 0) { // is_prime returns 1 aka. true
count++;
}
scanf("%d", &temp);
}
printf("%d\n", count);
}
int is_prime(int num) {
for (int j = 2; j < num; j++) {
if (num % j == 0)
return 1;
}
return 0;
}