c++ - Boolean function. Calling it and using True or false -
i need help function it's true numbers devided 2 numbers (1, , number itself). test function. user get's 3 numbers , has write if "only devided two". i'm not sure how phone call function user can anwser "yes" "no"
bool test_prastevil(int prastevilo) { int c=0; for(int i=1;i<=prastevilo;i++) { if(prastevilo%i==0) { c++; } } if (c==2) { homecoming true; //if(stevec==1)re++;} } else { homecoming false; } }
edit: part of post can deleted.:)
/*------------------------------------------------
for illustration function can written next way. assume 1 (or -1) satisfies condition.
bool test_prastevil(int prastevilo) { unsigned int value = std::abs( prastevilo ); unsigned int x = 1; while ( x * x < value && value % x != 0 ) x++; homecoming value != 0 && x * x == value; }
------------------------------------------------*/
if need function determine whether number prome (that excluding 1) can write
bool test_prastevil( int prastevilo ) { unsigned int x = std::abs( prastevilo ); bool prime = ( x == 2 ) || ( x % 2 != 0 && x != 1 ); ( unsigned int = 3; prime && * <= x; += 2 ) { prime = x % != 0; } homecoming prime; }
if not want consider signed values define parameter unsigned int
c++ function boolean
No comments:
Post a Comment