加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

判断是否是素数

(2007-06-25 14:55:11)
分类: 隨筆

                  #include <iostream.h>
                  int pream(int n)
                  {

                     int i;
                     for(i=2;i<=n-1;i++)

                             if(n%i==0) break;
                     if(i<=n-1)return 0;
                     else return 1;
                  }
                  void main()
                 {
                     cout<<"请输入一个数"<<endl;
                     int a;
                     cin>>a;
                     if(pream(a))cout<<"是素数"<<endl;
                     else cout<<"不是素数"<<endl;

                  }

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有