Today we are learn how to find prime number using ‘c language’ ? we all know that prime number is number which divided by itself or 1.
So we are check given number
by every number, to find given number is divisible by any number or not , for
that we are use a loop (in this programme we are use ‘while’ loop) and also use
relational operator and (if-else) .
Now I hope so that you are
understand what we are going to use in this program.
Now we are right programme to find prime number using ‘c language’.
SOURCE CODE:-
#include<stdio.h>int main(){ int i=2,n,p; printf("enter the number to find is prime or not="); scanf("%d",&n); while(i<n){ if(n%i==0){ p=1; break; } i++; } if(p==1 && n!=2){ printf("%d is not a prime number",n); } else{ printf("%d is a prime number",n); }
return 0;}
Output:-
enter the number to find is prime or not=7
7 is a prime
number
enter the number to find is prime or not=9
9 is not a prime number
//enter any other number or see the result
0 Comments