第8章第3讲变量存储类别及内外部函数
#include"stdio.h" void f(int a,int b) { int i,j; i=a+2; j=b-1; printf("函数f中:a=%d,b=%d\n",a,b); printf("函数f中:i=%d,j=%d\n",i,j); } main() { int i=4,j=5; f(i,j); printf("主函数中:i=%d,j=%d\n",i,j); }
#include"stdio.h" float s; float ls(float r) { float len; len=2*3.14*r; s=3.14*r*r; return len; } main() { float c,r; printf("请输入圆的半径:"); scanf("%f",&r); c=ls(r); printf("圆的周长为:%f\n",c); printf("圆的面积为:%f\n",s); }
#include"stdio.h" f(int a) { auto b=2; static c=3; b=b+1; c=c+1; return a+b+c; } main() { int a=1,i; for(i=1;i<=2;i++) printf("第%d次调用后结果:%d\n",i,f(a)); }
#include"stdio.h" void save() { int money; extern amount; printf("请输入存款金额:"); scanf("%d",&money); amount=amount+money; } int amount=10000; main() { save(); printf("余额为:%d元\n",amount); }