函数头为double power(double x,int n)。在主函数中输入x、n并调用该函数求 (函数定义在主函数后面,在调用前做函数声明)

输出x^n

 1 #define _CRT_SECURE_NO_WARNINGS 1
2 #include<stdio.h>
3 double power(double, int);
4 int main()
5 {
6 double x; int n;
7 puts("INPUT 'x', 'n'\n");
8 scanf("%lf%d", &x, &n);
9 printf("x^n = %lf", power(x, n));
10 return 0;
11 }
12 double power(double x, int n)
13 {
14 int i; double rst = 1;
15 if (n == 0)//i不会小于0
16 {
17 return 1;
18 }
19 else
20 for (i = 1; i <= n; i++)//常规思路
21 {
22 rst = rst * x;
23 }
24 return rst;
25 }
1 double power(double x, int n)//用递归
2 {
3 int i; double rst = 1;
4 if (n == 0) return 1;
5 else return x * power(x, n - 1);
6 }

最新文章

  1. 使用神经网络来识别手写数字【译】(三)- 用Python代码实现
  2. A way to connect to network through WIFI on Centos 7
  3. A Study of WebRTC Security
  4. vundle按照YouComplete
  5. IOS 网络浅析-(五 xml解析)
  6. 不等高cell搭建(二)
  7. Python生态环境简介[转]
  8. 李洪强漫谈iOS开发[C语言-028]-逗号表达式
  9. Plan : 破晓
  10. ruby错误
  11. C++大数精度计算(带小数点)
  12. IP协议和网络传输中的封装与分用。
  13. NGUI_slider
  14. leetcode — convert-sorted-list-to-binary-search-tree
  15. idea创建项目报错(Maven execution terminated abnormally (exit code 1) )解决方案
  16. Spring framewrok 源码概览
  17. 黄聪:visual studio 2017编译运行出现脚本发生错误等问题如何解决?
  18. 记账本,C,Github,entity
  19. 小朋友学C语言(1):Hello World
  20. UNITY 的GC ALLOC到底是什么

热门文章

  1. 【Hive 元数据和真实数据-TAB_COL_STATS记录错误问题】
  2. Java获取当前服务器域名、IP、端口
  3. usb 2.0 high speed resetting signaling.
  4. easyui subGrid实现
  5. Attention:何为注意力机制?
  6. sqlyog连接hive解决方案
  7. php 图片加水印插件
  8. c中遍历lua的表
  9. git stash (pycharm/vscode的gui演示)
  10. WPF中向下拉框中绑定枚举体