Header Ads

Prime number

How to check prime number in C?

    prime number:- prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

                       Logic is here now we need to develop a program for checking whether the provided number by user is prime or not prime.

Program :- 



#include<stdio.h>
#include<conio.h>
main()
{
      int n,i=1,a;
      printf("enter the number: ");
      scanf("%d",&n);
      i=i+1;
      if(i<=n/2)
      {
                   a=n%i;
                   a!=0;
                   i++;
                   printf("prime number");
                   }
      else
      printf("not a prime number");
      
      
      getch();
      
      }

The above program is for checking prime number from the number provided by user on user screen.Output of the above program is below.

Output :-

enter the number: 17
prime number_


17 is a prime number because it is satisfying the condition for being a prime number. You may check itself by giving different values.

No comments