prob2-w2

mail@pastecode.io avatar
unknown
plain_text
a year ago
877 B
1
Indexable
Never
#include <stdio.h>
#include <conio.h>
#include <math.h>

int checkPrimeNumber(int num){
	int i; 
	if (num > 2){
		for (i = 2; i < num; i++){
			if (num % i == 0){
				return 0;
			}
		}
		return 1;
	} else if (num == 2){
		return 1;
	}  
	return 0;
}

int inputLengthOfSeq(){
	int n = -1; 
	while (n <= 0){
		printf("Input your valid length N = ");
		scanf("%d", &n);
	}
	return n; 
}

void inputSeq(int * seq, int length){
	for (int j = 0; j < length; j++){
		printf("Input your %d number: ", j);
		scanf("%d", (seq + j));
	}
}


int main(){
	int N; // length declaration 
	N = inputLengthOfSeq();
	int seq[N];
	inputSeq(seq, N);
	printf("The original sequence: ");
	for (int i = 0; i < N; i++){
		printf("%d, ", seq[i]);
	
	}
	printf("\nThe prime numbers: ");
	for (int j = 0; j < N; j++){
		if (checkPrimeNumber(seq[j]) == 1){
			printf("%d ", seq[j]);
		}
	}
	return 0; 
}