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