+ 1
Fix it for me plz prime nimber
#include<stdio.h> int main() { int s=0,i,n,count=0; printf("Enter a positive number:"); scanf("%d",&n); for(i=1;i<=n; i++) { if(n%i==0){ printf(" %d \n",i); count++; } } if(count==2){ printf("Prime"); } else{ printf("Not Prime"); } return 0; }
2 Réponses
+ 1
C
int n;
scanf("%d",&n);
int p=1;
for (int i=2; i<n; i++) if (n %i == 0) {p=0; break;}
if (p==1)
printf("%d %s\n", n,"is a prime number");
else
printf("%d %s\n", n,"is not a prime number");
https://code.sololearn.com/cn7bc0Uk3evY
C#
public static bool chkPrime(int num)
{
for (int i=2; i<num; i++) if (num %i == 0) return false;
return true;
}
https://code.sololearn.com/cJqJ46Lalczq
0
Typo is there... If(count==2).. And remove unused variable like s