/******************/ /* playing around */ /******************/ /************************************************************** * * New syntax: the "while" loop * New #include: math.h has sin, cos, and so on. * New %.42g in printf format means "print 42 digits after decimal" * New funky form for this (long) comment - but it's still a bunch of * stuff between the "start comment" / * and "end comment" * / * (I left spaces there so those wouldn't stop this comment...) * * Note the indentation of stuff within main(){ vs stuff in while(){ * loop - this helps you see what's what. * * Note also the use of the constants XMAX and XMIN, rather than * "hard coding" those into the middle of the program. This is * good form and helps you see what's what. People typically * use ALL_CAPITALS for constants (things that won't change) and * lower_case for things that will. But be clear that This and * THIS and tHis are all different variables in C ... * * Are we having fun yet? * ***************************************************************/ #include #include main() { double x,y,dx; double XMIN = 0.0; double XMAX = 10.0; /* --------- read inputs ----------- */ printf(" dx = ? "); scanf("%lf", &dx); printf(" OK, dx = %g \n", dx); /* --------- loop over x --------- */ x = XMIN; while ( x < XMAX ) { y = sin(x); printf(" x = %g, sin(x) = %.42g \n", x, y); x = x + dx; } printf(" Done \n "); }