+ 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; }

2nd Dec 2021, 11:53 AM
Ls Lisan
Ls Lisan - avatar
2 Respostas
+ 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
2nd Dec 2021, 12:46 PM
SoloProg
SoloProg - avatar
0
Typo is there... If(count==2).. And remove unused variable like s
2nd Dec 2021, 11:58 AM
Pranshu Sachan