Don’t worry, unlock all articles / blogs on PrepInsta by just simply logging in on our website
Automata Questions – 8
June 23, 2019
Q8. Print the prime numbers from an array up to given value n by using existing function. int isprime(int num) { // type your code here } int main() { int n, m, arr[100], size=0, i; scanf(“%d”, &n); for(m = 2; m <= n; m++) { if(isprime(m)) { arr[size++]= m; } } for(i = 0; i < size; i++) { printf(“%d\n”, arr[i]); } return 0; } Answer: int isprime(int num) { int i; int isprime = 1; for(i = 2; i <= num / 2; i++) { if(num % i == 0) { isprime = 0; break; } } return isprime; }
Login/Signup to comment