Ad Code

NEW POST

6/recent/ticker-posts

write a program to check weather a enter number prime or not.

... 
CONCEPT:
 
we know that the prime number is divided from 1 and itself  so i used this condition in if else condition 
if(n%n==0&&n%2!=0&&n%3!=0&&n%5!=0&&n%7!=0) then print prime and in else if condition
else if(n==2||n==5||n==3||n==7) it is also prints prime number if conditions false then print not prime below is the code:.


CODE

//write a program to check weather a enter number prime or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("enter any number to check prime or not");
scanf("%d",&n);
if(n%n==0&&n%2!=0&&n%3!=0&&n%5!=0&&n%7!=0)
{
printf("prime");
}
else if(n==2||n==5||n==3||n==7)
{
printf("prime");
}
else
{
printf("not prime");
}
getch();
}

Post a Comment

0 Comments