for (int i=1;i<a; i=i*10){ int b= a/i; if (b%2==0) even++; else odd++; }