编程介的小学生 2019-03-11 00:52 采纳率: 20.5%
浏览 674

打印输出范围内素数的个数有多少,采用C编程语言方式的实现

Problem Description
Give you a lot of positive integers, just to find out how many prime numbers there are.

Input
There are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won’t exceed 32-bit signed integer, and each of them won’t be less than 2.

Output
For each case, print the number of prime numbers you have found out.

Sample Input
3
2 3 4

Sample Output
2

  • 写回答

2条回答 默认 最新

  • qq_37664296 2019-03-11 09:23
    关注

    只会java的,应该差不多吧

    Scanner sc = new Scanner(System.in);
            System.out.println("输入起始:");
            int beginNum = sc.nextInt();
            System.out.println("输入结束:");
            int endNum = sc.nextInt();
            if(endNum>beginNum)
            {
                for(int i = beginNum;i<=endNum;i++)
                {
                    boolean isPrime = true;
                    for(int j = 2;j<=Math.sqrt(i);j++)
                    {
                        if(i%j==0)
                        {
                             isPrime = false;
                             break;
                        }
                    }
                    if(isPrime)
                    {
                        System.out.println(i);
                    }
                }
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料