Write a C Program to check if the number is prime number or not

Write a program in the C programming language to check if the inputted number is a prime number or not. In this program for loop is used to create numbers from 2 to n-1 to check if they are divisible by n or not and if any of them is divisible then the control is transferred outside the for loop by using the break statement and the result is printed in negative. Below is the code of the program –

/* C Program to check if number is prime number or not */

void main()
     int n,i,ct=0,rd=0;

     printf("Enter any number \n");


            printf("\n %d is prime number",n);
            printf("\n %d is not prime number",n);


Input – 23
Output – 23 is a prime number

yashan has written 69 articles

11 thoughts on “Write a C Program to check if the number is prime number or not

  1. The holiday happens to coincide with the end-of-the-season for
    many of the Island’s young summer employees and brings on a last chance for partying hearty on Mackinac Island. People will say just about anything to get you out to their property to see a horse, in the hopes of selling you something else they might have. Morgan is a breed of horse very much desired by the horse community as they entertain all riding disciplines.

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=""> <s> <strike> <strong>