//* Different loops for the same task: calculation of integer power *

/**********************/ double ipow1 ( double x, int n ) { double result=1.0; if (x==0.0) return(0.0); if (n<0) { n=-n; x=1.0/x; } for (int cnt=1; cnt<=n; cnt++) result*=x; return(result); } /**********************/ double ipow2 ( double x, int n ) { double result=1.0; if (x==0.0) return(0.0); if (n<0) { n=-n; x=1.0/x; } for (int cnt=n; cnt>1; cnt--) result*=x; return(result); } /**********************/ double ipow3 ( double x, int n ) { double result=1.0; if (x==0.0) return(0.0); if (n<0) { n=-n; x=1.0/x; } for ( ; n>0; n--) result*=x; // actually there is no need for cnt because n is a local variable return(result); }