① 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。