c program to find prime number

c program to find prime number. In this C program, we will input the number when program runs and find whether that entered number is prime or not. You can also refer for co- prime numberThis program uses “%” or “modulus” operator which gives the remainder of two numbers when it is divided. We can also find prime number using recursion.
For example : 7 % 2 = 1, as 1 is remainder when 7 is divided by 2. So if the number is not prime number then its % operation will give output ‘0’ otherwise it is prime number.

c program to find prime number

#include<stdio.h>                     // Including library
#include<conio.h>
int main()
{
    int n; 
    int i; 
    printf(" enter the number : ");   //taking numbers
    scanf("%d",&n);
    for(i=2; i<n; i++)
    {
        if(n%i==0)                //condition for prime number
        {
            printf("%d is not a prime number.", n);
            getch();          // hold  the  screen to display the above message
            return (1);            // return statement  will return the value                                                                      }
        }
    printf("%d is a prime number.", n);        //printing the result
    getch();
}
Lets see the output c program to find prime number.

Output of c program to find prime number:

c program to find prime number
c program to find prime number

Add Comment Register



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>