Saturday, February 24, 2024

6. Write a function to find whether a given no. is prime or not. Use the same to generate the prime numbers less than 100.

 #include <stdio.h> 

int checkPrime(int N) 

int flag = 1; 

for (int i = 2; i <= N / 2; i++) { 

if (N % i == 0) { 

flag = 0; 

break; 

return flag ; 



int main() 

for(int i=1;i<=100;i++)

if(checkPrime(i)&&i!=1)

    printf("%d ",i);


return 0;

}


No comments:

Post a Comment