0
This is a code for find a number whether it's prime or not. Is this code incorrect ???? Thank you. 😊
#include <stdio.h> void main() { int a , count = 0; printf ("enter a number\n"); scanf("%d",&a); for(int i=1;i<=a;i++) { if((a%i==0) && (a%1==0)) count++; } if((count == 2) || (count == 1)) printf("%d is a prime number\n" , a); else printf("%d this is not a prime number\n" , a ); }
2 Antworten
+ 1
Yes it works but try it yourself in the code playground.
+ 1
You can improve it a little more. Looping upto sqrt(a) is enough, no need to loop upto full a.