Write a program in c to find prime number or not
Flowchart:
Algorithm:-
· Start
· Read number
· i=2
· while(i<n)
· if(n%i==0)
· f=1
· if(f==1) then print not prime
· else print prime
· end
Program:-
#include<stdio.h> #include<conio.h> void main() { int n,i,f; f=0; printf("Enter a number"); scanf("%d",&n); i=2; while(i<n) { if(n%i==0) { f=1; break; } i++; } if(f==1) printf("\n not a prime number"); else printf("\n prime number"); }
Output:-
Enter a number 7 prime number
Enter a number 8 not a prime number
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Flowchart:
Algorithm:-
· Start
· Read number
· i=2
· while(i<n)
· if(n%i==0)
· f=1
· if(f==1) then print not prime
· else print prime
· end
Program:-
Output:-
need an explanation for this answer? contact us directly to get an explanation for this answer