① c语言计算乘方
pow函数的y是int型的
另外,虽然没什么影响,但是不得不说你的anser写错了,是answer;还有就是你定义的函数完全没有意义了,定义的函数只是纯粹地调用了另一个已有函数
② c语言编程问题 急!!
拜托大哥把公式写正规一点好不好,是乘方就是乘方,不要乱写。
下面的运行结果不正确,你再查一下,看sin到底是怎么求的,稍微改一下就成了。
#include <iostream>
#include <cmath>
using namespace std;
int fatorial(int number)//阶乘递归函数;
{
if(number==1)
return 1;
else
{
return number*fatorial(number-1);
}
}
double sinfunction(double x)
{
double result = 0;
int i= -1;
for(int n = 1;n < 5;n++)
{
result=result+i*(n*2-1)*x/fatorial(n*2-1);
cout<<result<<endl;
i = (-1)*i;
}
return result;
}
int main()
{
cout<<sinfunction(10);
cout<<endl<<sin(10);
return 0;
}
第二道题目:
#include <iostream>
#include <cmath>
#define GIRTH(a,b,c) ((a+b+c)/2)
using namespace std;
float areaoftriangle(float a,float b,float c)
{
float s = GIRTH(a,b,c);
return sqrt(s*(s-a)*(s-b)*(s-c));
}
int main()
{
cout<<areaoftriangle(3,2,3);
return 0;
}
在宏里面怎么开方,我也没弄明白,如果想出来,怎么办,再补充。
③ c语言中乘方要怎么写
设求x的y次方,且y为int型,如果你是想通过调用库函数实现,则可如下调用
#include "math.h"
double a = pow(x, y);
若你想自己设计一个函数来求乘方,则可如下实现
double pow(double x, int y) {
int i;
double proct = 1.0;
for(i = y; i > 0; i--)
proct *= x;
return proct;
}
④ 怎样用编辑C语言计算乘方
#include<stdio.h>
intChengFang(intx,intn)
{
inttmp;
if(n==1)
returnx;
if(n==0)
return1;
if(n%2==0){
tmp=ChengFang(x,n/2);
returntmp*tmp;
}
tmp=ChengFang(x,(n-1)/2);
returntmp*tmp*x;
}
intmain()
{
intx,y;
x=ChengFang(3,4);
y=ChengFang(2,5);
printf("3^4=%d2^5=%d ",x,y);
}
⑤ C语言中表示一个数的次方怎样表示
c语言中表示乘方的函数为pow(),但是需要引入头文件:#include<math.h>
想表示一个数a的n次方的话,可以用如下代码:
#include<stdio.h>
#include<math.h>
intmain()
{
inta=10;
intn=2;
intres;
res=pow(a,n);//表示10的平方
return0;
}
⑥ c语言中怎么表示多次方
c语言中表示乘方的函数为pow()
头文件:#include <math.h>
函数原型:double pow(double x, double y);
函数说明:The pow() function returns the value of x raised to the power of y. pow()函数返回x的y次方值。
例:
#include<stdio.h>
#include<math.h>
voidmain()
{
doublepw;
inta=2;
pw=pow(a,10);//a的10次方
printf("%d^10=%g ",a,pw);
}
相关函数:
float powf(float x, float y); //单精度乘方
long double powl(long double x, long double y); //长双精度乘方
double sqrt(double x); //双精度开方
float sqrtf(float x); //单精度开方
long double sqrtl(long double x); //长双精度开方
⑦ c语言乘方函数
在C语言的头文件 math.h中定义了pow(x,y),返回结果是x的y次方。其中,x、y及函数值都是double型;具体使用时要先添加#include<math.h>。
在C++以及其他高级编程语言中都定义了此操作函数。C++中,乘方函数被定义在了头文cmath头文件下。具体使用时,需先引用头文件#include <cmath>。
对于64位长整型数据进行乘方计算,pow函数已无法满足其精度需要,这里需要通过长整型数的四则运算来实现。
乘方函数名称:pow(double,double), 具体参数中至少一方为float、double、long double类型。如计算5³;时, 直接使用 pow(5,3);返回结果即记为125。