C Program to Detection of a Prime Number

How to write a C Program to Detection of a Prime Number in C Programming Language ?

Write a program to determine whether a number is prime or not. 

Note :A prime number is one, which is divisible only by 1 or itself. 

  1. #include<stdio.h>
  2. main()
  3. {
  4. int num, i;
  5.  
  6. printf ("Enter a number:");
  7. scanf ("%d", &num);
  8.  
  9. i=2;
  10. while (i<=num - 1)
  11.  
  12. {
  13. if (num % i ==0)
  14.  
  15. {
  16. printf ("Not a prime number");
  17. break;
  18. }
  19.  
  20. i++;
  21. }
  22.  
  23. if (== num)
  24.  
  25. printf ("Prime Number");
  26. }


Learn More :