#4702: 不知道錯在哪~~請各位大大幫我看一下


endavid (滔)


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int x,n;
    cin>>n;
    for(x=sqrt(n);x>0;x--)
    {
        if(n%x==0)
        break;
    };
    if(x!=1)
    cout<<"非質數";
    else
    cout<<"質數";
     return 0;
}
#4737: Re:不知道錯在哪~~請各位大大幫我看一下


linishan (L)


#include
#include
using namespace std;
int main()
{
    int x,n;
    cin>>n;
    for(x=sqrt(n);x>0;x--)
    {
        if(n%x==0)
        break;
    };
    if(x!=1)
    cout<<"非質數";
    else
    cout<<"質數";
     return 0;
}


你的程式只會判斷是不是1而已

前面做得完全不搭嘎 ..

請自己測過在發問.. 好習慣..

#4752: Re:不知道錯在哪~~請各位大大幫我看一下


linishan (L)


對不起 上一篇我看錯了

你沒有多筆測資輸入 .