c - Finding prime numbers is giving me errors -
i wanted print divisors of given range of numbers. works alright. when try modify put ****
@ end of prime number's divisors acts bizarre.
#include <stdio.h> int main() { int a,start,rounds,b,c,k=0; printf("please enter number start :"); scanf("%d",&start); printf("please enter how many numbers want print number :"); fflush(stdin); scanf("%d",&rounds); for(a=start;a<=start+rounds;a++) { printf("\n\nthe divisors of number :%d \n",a); for(b=1;b<=a;b++) { c=a%b; if(!c) { k++; printf("%d\n",b); } } //printf("%d",k); if((k==2)||(k==1)) printf("***\n"); } getchar(); return 0; }
ps:- trick used find prime number counting how many printf
statement has been executed before loop ends. there wrong it? when remove //
printf
statement prints below.
start=========>k 1 =========>1 2 =========>3 3 =========>5 4 =========>8 5 =========>10
why that?
if((k==2)&&(k==1))
there no way in todays computers k can 2 and 1 @ same time. maybe meant if k 2 or k 1 ?
Comments
Post a Comment