全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
1283 0
2017-09-17

题目是这样的:

/* QUESTION

Write a short program that that prints all prime numbers to a log file between

2 and 1000. Your program can assume 2 and 3 are prime numbers from the outset.*/

把2~1000里所有的质数,展示在log文件里,可以设定2,3是已知质数


下面是我写的命令,作为一个小白,看不出来哪儿错了,但是一直在报错

clear all

set more off

cap log close


global Primes 2 3


forvalue i=4/1000{

        local isPrime = 1

       

        foreach n of Prime{

                local reminder = mod(`i',`n')

               

                if reminder == 0 {

                        local isPrime = 0

                }

        }

       

        if isPrime == 1 {

                global Primes $Primes `i'

        }

}         

display "Prime numbers are $Primes"



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群