《函数 的 执行》由会员分享,可在线阅读,更多相关《函数 的 执行(15页珍藏版)》请在金锄头文库上搜索。
1、【例5-1】 输入圆柱体的高和半径,求圆柱体积。volume=*r2*h。要求定义和调用函数cylinder (r, h )计算圆柱体的体积。,#include int main( void ) double height, radius, volume;double cylinder (double r, double h); /* 函数声明*/printf (Enter radius and height: );scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height ); /* 函数调用*/printf (Vol
2、ume = %.3fn, volume);return 0;,例5-1源程序,double cylinder (double r, double h) /* 函数定义*/double result;result =3.1415926 * r * r * h; /* 计算体积 */return result; /* 返回结果 */,#include int main( void ) double height, radius, volume;double cylinder (double r, double h); printf (Enter radius & height:n );scanf
3、(%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926 * r * r * h; return result; ,输出窗口,内存,.,输出窗口,#include int main( void ) double height, radius, volume;double cylinder (double r, d
4、ouble h); printf (Enter radius & height:n );scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926 * r * r * h; return result; ,#include int main( void ) double height, radius,
5、volume;double cylinder (double r, double h); printf (Enter radius & height:n );scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926 * r * r * h; return result; ,输出窗口,#include
6、int main( void ) double height, radius, volume;double cylinder (double r, double h); printf (Enter radius & height: n);scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926 * r
7、 * r * h; return result; ,输出窗口,Enter radius & height:,输出窗口,Enter radius & height:3.010,#include int main( void ) double height, radius, volume;double cylinder (double r, double h); printf (Enter radius & height: n);scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume =
8、 %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926 * r * r * h; return result; ,输出窗口,Enter radius & height:3.010,#include int main( void ) double height, radius, volume;double cylinder (double r, double h); printf (Enter radius & height: n);scanf (%lf%lf, &r
9、adius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926 * r * r * h; return result; ,输出窗口,Enter radius & height:3.010,内存,#include int main( void ) double height, radius, volume;double cylinder (d
10、ouble r, double h); printf (Enter radius & height: n);scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926 * r * r * h; return result; ,输出窗口,Enter radius & height:3.010,#inclu
11、de int main( void ) double height, radius, volume;double cylinder (double r, double h); printf (Enter radius & height: n);scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926
12、* r * r * h; return result; ,输出窗口,Enter radius & height:3.010,内存,#include int main( void ) double height, radius, volume;double cylinder (double r, double h); printf (Enter radius & height: n);scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return
13、 0;double cylinder (double r, double h)double result;result =3.1415926 * r * r * h; return result; ,输出窗口,Enter radius & height:3.010,内存,#include int main( void ) double height, radius, volume;double cylinder (double r, double h); printf (Enter radius & height: n);scanf (%lf%lf, &radius, &height);volume = cylinder (radius, height );printf (Volume = %.3fn, volume);return 0;double cylinder (double r, double h)double result;result =3.1415926 * r * r * h; return result; ,