#9217: 在c++答案正確 這裡卻WA??求解


wei09955104 (wei)


我是個自學新手 遇到如上問題........

 

請問哪裡出錯了??

#include<iostream>
using namespace std;
int test(int b)
{
  int i;
  for(i=2;i<=b-1;i++)
   {
    while(b%i==0)
    return 0;                         
     
   }
}


int main()
{
    int a;
    while(cin>>a)
    {
     if(test(a)==0)
     cout<<"非質數"<<endl;
     else
     cout<<"質數"<<endl;
    }
   
   
 return 0;  
}

#9250: Re:在c++答案正確 這裡卻WA??求解


ak5612599 (魂o小草)


2是質數喔!!!