TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">//编写一函数判断一个数是否为素数
- #include<stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void f61(int a )
- {
- if (a==0)
- {
- printf("%d不是素数!",a);
- }
- else if (a==1)
- {
- printf("%d不是素数!",a);
- }
- else
- {
- int flag=1;
- for (int i=2;i<=sqrt((double)a);i++)
- {
-
- if (a%i==0)
- {
- flag=0;
- break;
- }
- }
- if (flag==1)
- {
- printf("%d是素数!",a);
- }
- else
- printf("%d不是素数!",a);
- }
- }</pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">void main()
- {
- int a;
- scanf_s("%d",&a);
- f61(a);
- system("pause");
- }
-
- </pre></pre>
|
|