第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關(guān)于素數(shù)的問題

關(guān)于素數(shù)的問題

C
曾小妍 2015-12-03 11:39:09
求一個數(shù)是素數(shù)的代碼
查看完整描述

1 回答

?
流浪_老

TA貢獻71條經(jīng)驗 獲得超14個贊

找了一個 懶得編寫

#include <stdio.h>

bool isPrimeNum(int x)

{

? ? if (x == 1)

? ? ? ? return false;

? ? else if (x <= 0)

? ? ? ? return false;

? ? else if (x == 2)

? ? ? ? return true;

? ? else

? ? {

? ? ? ? for (int i = 2; i < x; i++)

? ? ? ? {

? ? ? ? ? ? if (x%i == 0)

? ? ? ? ? ? ? ? return false;

? ? ? ? }

? ? ? ? return true;

? ? }

}

int main(void)

{

? ? int x;

? ? char ch;

? ? do{

? ? printf("請輸入一個大于1的自然數(shù):\n");

? ? scanf("%d", &x);

? ? if (isPrimeNum(x) == false)

? ? ? ? printf("%d不是素數(shù)\n",x);

? ? else if (isPrimeNum(x) == true)

? ? ? ? printf("%d是素數(shù)\n",x);

? ? printf("是否繼續(xù)(y/n):\n");

? ? scanf("%c", &ch);

? ? }while ('y'== ch || 'Y' == ch);

? ? return 0;

}


查看完整回答
反對 回復(fù) 2015-12-03
  • 1 回答
  • 0 關(guān)注
  • 1330 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號