C语言中求变量的平方或立方怎样打出来

来源:百度知道 编辑:UC知道 时间:2024/05/10 08:05:24
阶乘用什么符号表示谢谢

都可以用递归搞定:

#include <stdio.h>

double factorial(int n)
{
return n > 0 ? n * factorial(n-1) : 1;
}

double power(int x, int y)
{
if(y > 0)
return y > 0 ? x * power(x, y-1) : 1;
else
return 1 / (y < 0 ? x * power(x, (-y)-1) : 1);
}

int main()
{
double a = power(3, 5); // 3^5
double b = power(3, -5);// 3 ^-5
double fac = factorial(10); // 10! = 10 * 9 * 8 *````* 2 * 1
printf("10! = %lf\n", fac);
printf("3的 5次幂: %lf\n", a);
printf("3的-5次幂: %lf\n", b);
}

计算机里没有定义阶乘的表示符号,数学上用惊叹号表示,比如5!就等于5 * 4 * 3 * 2 * 1所以等于120。

楼上的我都同意!
都是正确答案!^_^!
阶乘没有符号表示的!阶乘是用递归调用来实现的!

x的y次幂 pow(x,y)
要调用头文件math.h

double PingFang(double x) {

return x*x;
}
double LiFang(double x) {

return x*x*x;
}