標(biāo)題: 簡(jiǎn)單的C語(yǔ)言判斷素?cái)?shù)的源代碼 [打印本頁(yè)]

作者: yangsamson    時(shí)間: 2018-2-23 08:44
標(biāo)題: 簡(jiǎn)單的C語(yǔ)言判斷素?cái)?shù)的源代碼
#include<stdio.h>

int main()
{
        int x;
       
        for(x=2;x<100;x++)
        {
                int i;
                int isPrime=1;
                for(i=2;i<x;i++)
                {
                        if(x%i==0)
                        {
                                isPrime=0;
                                break;
                        }
                }
                if(isPrime==1)
                {
                        printf("%d ",x);
                }
        }
        printf("\n");
        return 0;
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1