Aim:
To
write a C program to check the prime number.
Algorithm
- Start the program
- Read the number ‘num’ from the user.
- For all i>num/2 divide the number by i.
- If the number is divisible by any other numbers then that number is not a prime number.
- If the number is not divisible by any other numbers then that number is a prime number.
- Display the result
- Stop the Program
#include<stdio.h>
#include<conio.h>
Void main()
{
int num,I;
clrscr();
printf(“\nEnter a number”);
scanf(“%d”,&num);
for(i=2;i<=num/2;i++)
{
If(num % i==0)
Break;
}
If (i>num/2)
Printf(“the given number %d is
prime”,num);
else
printf(“The given number %d is not
prime”,num);
getch();
}
Output - checking Prime
Number
Enter a number 56
The given number 56 is not prime
Enter a number 3
The given number 3 is prime
No comments:
Post a Comment