现在的位置: 首页 > 新课程 > 正文

结构化程序设计的基础:函数

2011年11月07日 新课程 ⁄ 共 279字 ⁄ 字号 暂无评论

1)函数定义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
int main(int argc, char *argv[])
{
	int base, n;
	int result =1;	
	int i;
 
	scanf("%d%d", &base, &n);
	for (i=1; i<=n; i++)
	    result = result * base;
 
	printf("%d\n", result);
 
	return 0;
}

2)函数的调用

1
2
 #include <math.h>
  double pow( double base, double exp );

3)函数的实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[])
{
	int base, n;
	int result;
 
	scanf("%d%d", &base, &n);
	result = pow(base, n);
 
	printf("%d\n", result);
 
	return 0;
}

抱歉!评论已关闭.