Pages

Friday, 1 February 2019

PRIME NUMBER IN C PROGRAM

PRIME NUMBER:
                   A NATURAL NUMBER GREATER THAN ONE HAS ANY OTHER DIVISORS EXCEPT 1 AND ITSELF IN OTHER WORDS WE CAN SAY WHICH HAS ONLY TWO DIVISORS 1 AND NUMBER ITSELF 

FOR EXAMPLE: 5 DIVISORS ARE 1 AND 5 

FOR EXAMPLE : 7 DIVISORS ARE 1 AND 7

PROGRAM:
// program to illustrate prime number
#include<stdio.h> // header section
int count; // global section
void main()
{
 int n,i=1;
 printf("Enter any number:");
 scanf("%d",&n);
 while( i <= n )
  {
   if((n % i == 0) && (n % n == 0))
     count++;
   i++;
  }
 if (count == 2)
   printf("%d is a prime number",n);
 else
   printf("%d is not a prime number",n);
}


output:

No comments:

Post a Comment

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...