Tuesday, 16 June 2015

C program to check number is prime or not.

WAP to check whether number is prime or not.
Program:
#include<stdio.h>                   
#include<conio.h>

int main()
{
       int n,i,a=0;  //Declaring Variable.
      
       printf(" enter the number : "); //For printing
       scanf("%d",&n);   //For Input.
        for(i=2; i<n/2; i++)  //For Loop.
        {
                if(n%i==0)
                {
                    a=1;
                    break;
                }
        }
    if(a==0)
       printf("%d is a prime number.",n); //For printing
    else
       printf("%d is not a prime number.",n);  //For printing
   getch();  //Getting a chracter or waiting for key press.
  return 0;
}

Output:

Video Explanation
Sorry Guys Explanation of this tutorial will be posted later this month.

No comments:

Post a Comment