To check whether a number is Prime in C
#include <stdio.h>#include <string.h>int main(){// To check whether a number is prime:int m,count=0;printf("Enter the number : ");scanf("%d",&m);for(int i=2;i<m;i++){if(m%i != 0){count=count +1;}else{continue;}}if(count == m-2){printf("%d is a Prime number\n",m);}else{printf("%d is not a Prime number\n",m);}return 0;}
Comments
Post a Comment