首页
/
每日頭條
/
生活
/
c語言求1000以内的素數
c語言求1000以内的素數
更新时间:2024-11-16 02:09:27

c語言求1000以内的素數?#include "stdafx.h"#include <stdlib.h>,我來為大家科普一下關于c語言求1000以内的素數?以下内容希望對你有幫助!

c語言求1000以内的素數(C語言學習---求一個正整數以内的素數)1

c語言求1000以内的素數

C語言學習 程序練習 求一個正整數以内的素數代碼如下:

#include "stdafx.h"

#include <stdlib.h>

int main()

{

int i,j=2;

int value;

int prime;

bool flag=false;

scanf_s("%d", &value);

for (i = 2; i < value; i )

{

for (j = 2; j <i; j )

{

prime = i%j;

if (prime == 0)

{ flag = true;

break; }

else

{ flag = false; }

}

if (flag==false && i>=2)

{ printf("this is prime %d in below %d \n",i,value);}

}

system("pause");

return 0;

}

運行結果:

輸入100

this is prime 2 in below 100

this is prime 3 in below 100

this is prime 5 in below 100

this is prime 7 in below 100

this is prime 11 in below 100

this is prime 13 in below 100

this is prime 17 in below 100

this is prime 19 in below 100

this is prime 23 in below 100

this is prime 29 in below 100

this is prime 31 in below 100

this is prime 37 in below 100

this is prime 41 in below 100

this is prime 43 in below 100

this is prime 47 in below 100

this is prime 53 in below 100

this is prime 59 in below 100

this is prime 61 in below 100

this is prime 67 in below 100

this is prime 71 in below 100

this is prime 73 in below 100

this is prime 79 in below 100

this is prime 83 in below 100

this is prime 89 in below 100

this is prime 97 in below 100

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2024 - www.tftnews.com All Rights Reserved