當前位置:編程學習大全網 - 電腦編程 - c語言輸出3到100的素數並統計個數的怎麽寫

c語言輸出3到100的素數並統計個數的怎麽寫

#include <stdio.h>

int isprime(int n)

{ int i;

for(i=2; i*i<=n; i++)

if(n%i==0)return 0;

return 1;

}

int main()

{ int i,n=0;

printf("3到100的素數:\n");

for(i=3; i<100; i++)

if(isprime(i))

{ printf("%d ",i);

? n++;

}

printf("\n個數=%d\n",n);

return 0;

}

  • 上一篇:編程不會怎麽考教資
  • 下一篇:1到100的完全數有幾個如題 謝謝了
  • copyright 2024編程學習大全網