Code to check the given number is prime number or not in C language

 Hello there!

techbincloud.blogspot.com

    Welcome to our blog. in this blog we will see how to write code to check the given number is a prime number or not. believe the code is very simple and clear.  


                                                        
Algorithm of the program
Firstly, we will see the algorithm to acquire awareness about the program i.e, how the program will work a step by step process.

  The steps are involved in algorithm 6.

There are:

Step 1: Start 

Step 2: Initialize variables

              flag<-1

              i=2

Step 3: Read n from the user.

Step 4: Repeats the steps until I>(n/2)

       4.1  If the reminder of n÷i equals 0

              flag=0

              Go to step 5

       4.2  i=i+1

Step 5: If flag=0

              Display n is not prime 

         else

              Display n is prime 

Step 6: Stop

 To better understand the program take look at the flow chart program here is the flow chart

                                                            Flowchart of program

techbin cloud
flow chart of the program

   Its program time lets see the program

Program

#include #include int main() { int i, a, b = 0; printf("enter a number"); scanf("%d", &a); for (i = 2; i <= a/2; i++) { if (a % i == 0) { b = 1; break; } } if (b == 1) { printf("given number not prime"); } else { printf("given number prime"); } return 0; }

Output

techbin cloud
output of program



ok, if you have any doubt feel free to contact us. if you want any program in C language please comment we will try my level best.                                    

                                                    Thank you for visiting

Post a Comment

0 Comments