Write a c program to find prime numbers






Write a program to find prime numbers in c programming language. Source code:


#include<stdio.h>
#include<math.h>

int main(){


  int num,i,count=0;

  printf("\nEnter any integer number :");
  scanf("%d",&num);

  for(i=2;i<=sqrt(num/2);i++){
        if(num%i==0){
           count++;
           break; //to exit from for loop
        }
  }

  if(count==0)
        printf("%d is a prime number",num);
  else
        printf("%d is not a prime number",num);

  return 0;
}




Post a Comment