34: W.A.P. to decide whether number is prime or not.
Please follow me for more practicals....
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int num, i;
printf("Enter num = ");
scanf("%d", &num);
for (i = 2; i < num; i++)
{
if (num % i == 0)
break;
}
if (i == num)
printf("%d is prime.",
num);
else
printf("%d is not
prime.", num);
getch();
}
Please follow me for more practicals....
Output:
Enter num = 7
7 is prime.
Please follow me for more practicals....
Algorithm:
1.
START
2.
Declare num, i = 2.
3.
Enter the num.
4.
Repeat upto step-6 until i < num.
5.
If (num % I == 0) then goto step-7.
6.
i++.
7.
If (I == num) then goto step-8 else goto step-9.
8.
Display num is prime, then goto step-10.
9.
Display num is not prime.
10.
STOP.
Please follow me for more practicals....
Flowchart: