To find given number is prime number or not
A number is said to be a prime number if the number is divisible by 1 and itself only.
If the given number is a prime them output should be 'the given number is prime' .If not the output should be The given number is not a prime number.
If the given number is a prime them output should be 'the given number is prime' .If not the output should be The given number is not a prime number.
INPUT: 5
OUTPUT: The given number is a prime number
INPUT: 4
OUTPUT: The given number is not a prime number
Program:
| #include<stdio.h> |
#include<conio.h>
int main()
{
int n, i, c = 0;
clrscr();
printf("\n Enter a number: ");
scanf("%d ", &n);
i=1;
do
{
if(n % i = 0)
c ++;
}while(i <= n)
(c == 2)?printf("\nThe given number is prime") : printf("\nThe given number is not prime");
return 0;
}
Output:
| Enter a number : 5 The given number is prime |
No comments:
Post a Comment