返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.    int a,c=0;
  7.    cout<<"請輸入一個整數:";
  8.    cin>>a;
  9.    for(int b=1;b<=a;b++){
  10.    if(a%b==0){
  11.           c++;   
  12.               }
  13.            }
  14.    if(c==2){
  15.    cout<<a<<"是質數"<<endl;
  16.              }
  17.    else{
  18.    cout<<a<<"不是質數"<<endl;
  19.              }
  20.     system("pause");
  21.     return 0;   
  22. }
複製代碼

TOP

返回列表