源代碼:

創(chuàng)新互聯(lián)從2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都做網(wǎng)站、成都網(wǎng)站制作網(wǎng)站策劃,項目實(shí)施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元臨武做網(wǎng)站,已為上家服務(wù),為臨武各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220
#includestdio.h
void
main()
{
float
h,r,V;
float
pi=3.1415926;
printf("請輸入圓錐的半徑r,高h(yuǎn):\t");
scanf("%f,%f",r,h);
V=1.0/3*pi*r*r*h;
printf("圓錐的體積是:
V=%6.2f\n",V);
}
#includeiostream
#includecmath
#define N 3.1415
using
namespace std;
class Height
{
private:
float
h;
public:
Height(float h):h(h)
{}
float getheight()
{
return
h;
}
};
class Circle
{
private:
float
radius;
public:
Circle(float r):radius(r)
{}
float
getradius();
float area();
};
float
Circle::getradius()
{
return radius;
}
float
Circle::area()
{
return N*radius*radius;
}
class cone:public
Height,public Circle
{
private:
float line;
public:
cone(float
h,float r):Height(h),Circle(r)
{}
void getline();
float
surarea();
float volume();
void show();
};
void
cone::getline()
{
float a=getradius();
float
b=getheight();
line=sqrt(a*a+b*b);
}
float
cone::surarea()
{
return area()+N*getradius()*line;
}
float
cone::volume()
{
return area()*getheight()/3;
}
void
cone::show()
{
cout"圓錐的表面積為:"surarea()endl;
cout"圓錐的體積為:"volume()endl;
}
int
main()
{
cone
A(4,3);
A.getline();
A.surarea();
A.volume();
A.show();
return
0;
}
#include stdio.h
float pi=3.14;
void main()
{
float r,h;
printf("請輸入半徑r:\n");
scanf("%f",r);
if(r=0)
{
printf("非法輸入");
}
else
{
printf("請輸入高h(yuǎn):\n");
scanf("%f",h);
if(h=0)
{
printf("非法輸入");
}
else
{
float s=pi*r*r;
float v=s*h/3;
printf("體積v=%f\n",v);
}
}
}
//示例代碼
#include?stdio.h
#include?math.h
#define?PI?3.1415926
int?main()
{
float?r,h;
float?c,s,v;??//底面周長,表面積,體積
scanf("%f%f",r,h);
c=2*PI*r;??//底面周長
s=PI*r*(r+sqrt(r*r+h*h));?//表面積
v=PI*(r*r)*h/3;??//體積
printf("圓錐體的底面周長=?%.2f\n",c);
printf("圓錐體的表面積=?%.2f\n",s);
printf("圓錐體的體積=?%.2f\n",v);
return?0;
}
//示例運(yùn)行結(jié)果
3?5
圓錐體的底面周長=?18.85
圓錐體的表面積=?83.23
圓錐體的體積=?47.12
#includestdio.h
#include math.h
void f1(int h,int d)
{
double v;
v=h*3.14*(d/2)*(d/2)/3;
printf("v=%lf\n",v);
}
void f2(int h,int d)
{
double s;
s=3.14*(d/2)*(d/2)+sqrt(h*h+(d/2)*(d/2))*(3.14*d/2);
printf("s=%lf\n",s);
}
int main()
{
int h,d;
printf("輸入高:\n");
scanf("%d",h);
printf("輸入直徑:\n");
scanf("%d",d);
f1(h,d);
f2(h,d);
return 0;
}
試試這個吧,你的代碼錯誤少了一個應(yīng)用數(shù)學(xué)函數(shù)的頭文件math.h,main函數(shù)也沒有返回值類型,貌似體積公式也不對,還有就是數(shù)據(jù)類型的問題(這個代碼不會出錯,但是結(jié)果會有影響)。
scanf("%d%d",r,h);
這一句,"%d%d"指的是你輸入的格式,這里你設(shè)置成了兩個整形,因此輸入的時候要按照這個格式輸入,順帶一提這個連續(xù)連個整形我都不知道該如何實(shí)現(xiàn)。。。
修改為scanf("%d %d",r,h); // 兩個%d之間加一個空格
然后手動輸入的時候,輸入3 4
注意輸入的時候,3和4中間用空格隔開,然后回車即可
總得來說,你的問題在于你手動輸入的東西和你的scanf設(shè)定的格式不匹配,因此出現(xiàn)了不可預(yù)知的結(jié)果。
網(wǎng)站標(biāo)題:c語言函數(shù)求圓錐體積,c語言求圓錐的表面積
URL地址:http://chinadenli.net/article47/dsegphj.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站導(dǎo)航、響應(yīng)式網(wǎng)站、搜索引擎優(yōu)化、服務(wù)器托管、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)