标题:判断一个数是不是素数的问题,请大神们指教!!!
只看楼主
托马斯明
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-10-12
 问题点数:0 回复次数:2 
判断一个数是不是素数的问题,请大神们指教!!!
#include<stdio.h>
#include <math.h>
void main()
{int m,i,k;

 scanf_s("%d",&m);
 k= sqrt(m);
 for(i=2;i<=k;i++)
     if(m%i==0) break;
 if(i>k)printf("%d是素数",m);
 
 else printf("%d是合数",m);

}


出现的问题是:
1>------ Build started: Project: su shu, Configuration: Debug Win32 ------
1>Build started 2012/10/14 15:08:51.
1>InitializeBuildStatus:
1>  Touching "Debug\su shu.unsuccessfulbuild".
1>ClCompile:
1>  su shu.cpp
1>d:\hello\su shu\su shu\su shu.cpp(7): error C2668: 'sqrt' : ambiguous call to overloaded function
1>          d:\program files\vs2010\vc\include\math.h(589): could be 'long double sqrt(long double)'
1>          d:\program files\vs2010\vc\include\math.h(541): or       'float sqrt(float)'
1>          d:\program files\vs2010\vc\include\math.h(127): or       'double sqrt(double)'
1>          while trying to match the argument list '(int)'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.67
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
搜索更多相关主题的帖子: started include 
2012-10-14 15:09
Molafei
Rank: 1
等 级:新手上路
帖 子:6
专家分:9
注 册:2012-10-14
得分:0 
程序代码:
# include <stdio.h>
int main(void)
{
    int i;
    int m;
    scanf("%d", &m);
    for (i=2; i<m; ++i)
    {
        if (m%i == 0)
            break;
    }
    if (i == m)
        printf("Yes!\n");
    else
        printf("No!\n");
      return 0;
}

2012-10-14 15:58
托马斯明
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-10-12
得分:0 
3Q!
2012-10-15 22:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-383164-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.403299 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved