首页
/
每日頭條
/
生活
/
判斷這個數是否是素數c語言
判斷這個數是否是素數c語言
更新时间:2024-12-18 12:39:15

判斷這個數是否是素數c語言?代碼如下,輸入0時輸入結束#include <stdio.h>,我來為大家科普一下關于判斷這個數是否是素數c語言?下面希望有你要的答案,我們一起來看看吧!

判斷這個數是否是素數c語言(用C語言判斷一組數是否是素數)1

判斷這個數是否是素數c語言

代碼如下,輸入0時輸入結束

#include <stdio.h>

int main()

{

int a,b,c=1;

printf("輸入一個或多個數字,檢驗是否為質數(輸入0時結束)");

for(;;)

{

scanf("%d",&c);

if(c==0) break;

while(c<2)

{

printf("%d輸入數字有誤",c);

scanf("%d",&c);

}

for(a=1;c>a;)

{

a ;

b=c%a;

if(a==c)

{

printf("%d是素數 ",c);

break;

}

if(b==0)

{

printf("%d不是素數 ",c);

break;

}

}

}

}

,
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