zoukankan      html  css  js  c++  java
  • c++ 求2100内的素数问题

    最近在学习c++,从最基础的联系

    这也是很常见的问题

    View Code
    #include "stdafx.h"
    #include <iostream>
    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])
    {
        int j,i;
        int nums=0;//质数计数
        int s=0;   //质数之和
        for(i=2;i<=100;i++) { 
            bool isSushuo=true;
            for(j=2;j<i;j++){
                if(i%j==0)
                    break;
            }
            if(j==i){//说明比i小的都循环完了
                nums++;
                s+=i;
                if(nums%7==0){
                    cout<<i<<"\t"<<endl;
                }else{
                    cout<<i<<"\t";
                }

            }
        }
        cout<<endl;
        cout<<"2-100 所有的质数有:"<<nums<<""<<endl;
        cout<<"2-100 所有的质数之和为:"<<s<<endl;
        cin>>s;
        return 0;
    }

     

  • 相关阅读:
    bzoj3110
    idea 设置系列 各种乱码
    vim 系列
    idea 神键
    简单工厂,工厂方法,抽象工厂
    log4 按包进行日志输出
    maven依赖本地宝
    kafka 理论学习
    kafka windows环境搭建 测试
    linux 查找文件的命令
  • 原文地址:https://www.cnblogs.com/clc2008/p/2382791.html
Copyright © 2011-2022 走看看