• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

cxr119911

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

No.12 判断质数

#include "stdio.h"
#include "math.h"
#include "stdlib.h"
int pd(int k);
int main()
{int x;
printf("Input x:\n");
scanf("%d",&x);
if(x<=1)
printf("Wrong!\n");
else if(pd(x))
printf("x is a zhishu.\n");
else printf("x isn't a zhishu.\n");
system("pause");
}
int pd(int k)
{int i;
for(i=2;i<k;i++)
{if((k%i)==0)
return 0;}
return 1;
}

 

1.不要把;写成了:

2.求开方sqrt()必须是long float/float/double的类型,而x%3==0中的x必须是int

3.函数返回真假也是返回,不可用void.

posted on 2016-12-03 14:12  cxr119911  阅读(137)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3