# find no of even factor, express as %

• 04-19-2003
henry
find no of even factor, express as %
question: enter a number, find number of even factor and expressed as percentage

i have type in the code and compiled it sucessfully. But the reuslt wasn't expected (always come as 0). Can someone please help to solve the problem. I am using a blood shed dev cpp ver 4.01.
Here is my code

Code:

``` int c(int day) //find the even factor of day and expressed as percentage //pre: day>0 //post: return percentage {  int eFactor;//even factor  int tFactor;//total factor  int i;//control variable  int percent;//express as percentage    //initialization  eFactor = 0;  tFactor = 0;  for (i=1; i<=num; i++)  {   if (num%i==0)   {   tFactor++;   if (i%2==0)       eFactor++;   }//end if   }//end loop  percent = (eFactor / tFactor)* 100;  return percent; }//end c```
• 04-19-2003
ripper079
Also the if-clause
Code:

`if (num%i==0)`
is not neccesary.

Your function should return a double or a float and not an integer number.
• 04-19-2003
grib
As a minor point, the number of even factors will be equal to the number of times you can divide by 2.
Code:

```int num_even(int n) {     int num=0;     while(n>1 && n%2==0) {++num;n/=2;}     return num; } int num_odd(int n) {     n >>= num_even(n);     int num=0;     const int lim = ceil(sqrt(n));     for(int d=3;n>1 && d<=lim;d+=2) {         while(n%d==0) {             ++num;             n/=d;         }     }     return num; }```
also consider what happens with your loop on 12 (3*2*2) this should be 66% but yours(fixing round off) will return 50%