C語言(online c) 寫簡單的 程式 ( 輸入2個數值 印出2個數值間的質數及質數的個數 )
#include<stdio.h>
#include<math.h>
int main()
{
int x,y,i,j ,cnt=0 ,cnt2=0;
printf("輸入2個數值 由小到大\n");
scanf("%d %d", &x,&y);
printf("你輸入的2個數值=%d %d\n", x,y);
for (i=x;i<=y;i++)
{
cnt=0;
for (j=2;j<=i-1;j++)
{
if (i%j==0)
cnt++;
}
if (cnt==0)
{
printf("%d\t",i);
cnt2++;
}
}
printf("\n\n%d到%d的質數共有%d",x,y,cnt2);
return 0;
}
Stdin Inputs...
5 37
輸入2個數值 由小到大
你輸入的2個數值=5 37
5 7 11 13 17 19 23 29 31 37
5到37的質數共有10
訂閱:
張貼留言 (Atom)
Node-Red 抓取 opendata 的資料集產生AQI 空氣品質指
Node-Red 抓取 opendata 的資料集產生AQI 空氣品質指標 實現透過 Node-RED 抓取環境部 OpenData(空氣品質 AQI)資料,最核心的流程為: 注入觸發(Inject) → HTTP 請求(http request) → 解析 JSON 資料(Fu...
-
數位IC設計入門-Verilog combinational logic 8 to 1 Multiplexer 多工器 Behavioral Modeling (& Test Bench) //數位IC設計入門-Verilog combinationa...
-
Line 發報機 Python TKinter (CONFIG_LINE Message API_2.py) import serial import serial.tools.list_ports import tkinter as tk from tkinter import...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
沒有留言:
張貼留言