练习一
1.#include "stdio.h"
void love()
{
printf("say hello!");
}
int main()
{
love();
}
2.
#include "stdio.h"
#include "math.h"
double f(double x,double y)
{
double i,o;
i=x*x+y*y;
o=sqrt(i);
return o;
}
int main()
{
float x,y;
scanf("%f,%f",&x,&y);
printf("%f",f(x,y));
return 0;
}
练习二.全局变量和局部变量。
全局在静态存储区,全局变量是程序是整个程序都需要用到的,单独分出一块存储区保存,该存储区存储的数据不清空.
局部变量是函数退出时自动清空的,所以放在栈里做临时存储
#include "stdio.h"
#include "math.h"
int i=3;
int main()
{
int a;
a=i+1;
printf("%d",a);
}
#include "stdio.h"
#include "math.h"
int main()
{
int i=3;
int a;
a=i+1;
printf("%d",a);
}
i所放的位置的不一样,应该决定了它是全局变量还是局部变量,上述程序的前者i属于全局变量,后者属于局部变量。
练习三.阶乘函数
#include "stdio.h"
#include "math.h"
int g(int i)
{
int o;
int t=1;
for(o=1;o<=i;o++)
t*=o;
return t;
}
int main()
{
int o,t;
for(o=1;o<=10;o++)
{
printf("%d jiecheng is %d\n",o,g(o));
}
}