{
  "question_id": 7453758,
  "question_title": "编写程序：判断素数的个数",
  "question_content": "<p>在一个数组A中存放100个数据&#xff0c;用子函数判断该数组中哪些是素数&#xff0c;并统计该素数的个数&#xff0c;在主函数中输出该素数的个数</p>",
  "difficulty": "简单",
  "answer_id": 53436453,
  "answer_content": "<p>代码如下&#xff0c;如有帮助&#xff0c;请采纳一下&#xff0c;谢谢。</p>\n\n<pre>\n<code>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nint isPrime(int n)\n{\n\tint i &#61; 2;\n\tif(n&lt;2) return 0;\n\tfor (i&#61;2;i&lt;n;i&#43;&#43;)\n\t{\n\t\tif(n%i &#61;&#61; 0)\n\t\t\treturn 0;\n\t}\n\treturn 1;\n}\n\nint CountPrime(int a[],int size)\n{\n\tint i &#61;0,count &#61; 0;\n\t//统计素数个数\n\tfor (i &#61; 0;i&lt;size;i&#43;&#43;)\n\t{\n\t\tif(isPrime(a[i]))\n\t\t{\n\t\t\tprintf(&#34;%d &#34;,a[i]);\n\t\t\tcount&#43;&#43;;\n\t\t\tif(count%10 &#61;&#61; 0) //每10个一行\n\t\t\t\tprintf(&#34;\\n&#34;);\n\t\t}\n\t}\n\tprintf(&#34;\\n&#34;);\n\treturn count;\n}\n\nint main()\n{\n\tint a[100],i,count &#61; 0;\n\tfor(i &#61; 0;i&lt;100;i&#43;&#43;)\n\t\ta[i] &#61; rand()%1000;//生成0-999以内的随机数\n\t\n\tprintf(&#34;素数的个数:%d\\n&#34;,CountPrime(a,100));\n\treturn 0;\n}</code></pre>\n\n<p> </p>\n",
  "tag_name": "c语言",
  "cpp": "#include <stdio.h>\n#include <stdlib.h>\nint isPrime(int n)\n{\n\tint i = 2;\n\tif(n<2) return 0;\n\tfor (i=2;i<n;i++)\n\t{\n\t\tif(n%i == 0)\n\t\t\treturn 0;\n\t}\n\treturn 1;\n}\nint CountPrime(int a[],int size)\n{\n\tint i =0,count = 0;\n\tfor (i = 0;i<size;i++)\n\t{\n\t\tif(isPrime(a[i]))\n\t\t{\n\t\t\tprintf(\"%d \",a[i]);\n\t\t\tcount++;\n\t\t\tif(count%10 == 0) \n\t\t\t\tprintf(\"\\n\");\n\t\t}\n\t}\n\tprintf(\"\\n\");\n\treturn count;\n}\nint main()\n{\n\tint a[100],i,count = 0;\n\tfor(i = 0;i<100;i++)\n\t\ta[i] = rand()%1000;\n\tprintf(\"素数的个数:%d\\n\",CountPrime(a,100));\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600469944",
  "status": 1,
  "keywords": "算法初阶,基础知识,分治策略,证明主定理,对b的幂证明主定理",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/40.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "qq_41208975"
}