課程
/后端開發
/C
/C語言入門
用子函數實現判斷素數,主函數輸出素數 程序怎么寫⊙_⊙
2018-05-15
源自:C語言入門 6-8
正在回答
#include<stdio.h>
void sushu(int n1,int n2){
int i,j;
int count=0;
for(i=n1;i<=n2;i++){
for(j=2;j<i;j++){
if(i%j==0){
count=1;
break;
}
? ?}
if(count==0)
printf("%d是素數\n",i);
count=0;
int main(){
int n1,n2;
scanf("%d %d",&n1,&n2);
sushu(n1,n2);
舉報
C語言入門視頻教程,帶你進入編程世界的必修課-C語言
1 回答求1-100之間所有素數
2 回答求兩數間的素數和 我找不到我的bug
4 回答求素數
1 回答6-4數組作為函數參數// 數組與數組之間的元素是如何替換的??
1 回答找出0-50之間的所有素數,看不懂取素數的代碼的具體意思
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-05-16
#include<stdio.h>
void sushu(int n1,int n2){
int i,j;
int count=0;
for(i=n1;i<=n2;i++){
for(j=2;j<i;j++){
if(i%j==0){
count=1;
break;
}
? ?}
if(count==0)
printf("%d是素數\n",i);
count=0;
}
}
int main(){
int n1,n2;
scanf("%d %d",&n1,&n2);
sushu(n1,n2);
}