/* * This is a polished, corrected version of * ~comp210/Labs/lab12/wrongo.c. */ #include // get declaration of NULL #include // get declaration of printf int main() { double x; printf( "Enter a positive x, and I'll calculate how many doublings\n" ); printf( "of 1 it takes until x is met or exceeded: " ); scanf( "%lf", &x ); int n = 1, doublings = 0; for ( bool notDoneYet = (x > 0); notDoneYet; notDoneYet = (n < x) ) { n *= 2; doublings++; } printf( "ceil(log_2(%g)) = %d.\n", x, doublings ); return 0; }