Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- int main( )
- {
- int a=0 , x=2 , y=1 ;
- cin>>a;
- int b=sqrt(static_cast<double>(a));
- while(x<=b)
- {
- y=0;
- y=a%x;
- if(y==0)
- break;
- x++;
- }
- if(y==0)
- cout<<"合數"<<endl<<endl;
- else
- cout<<"為質數"<<endl<<endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment