c语言编写面积函数 c语言求面积保存小数

C语言函数求面积哥们 你main函数漏了一句, 你的r在调用shubanjing()时输入 , 但你main函数没调用shubanjing(),也没定义r 。
void main()
{
float mianji;
double r = shubanjing();//就这一句
mianji=qiumianji(r);//这里参数是r
printf("你所求三角形面积为:%f",mianji);
}
main函数没有定义你也没有输入r怎么能算出面积呢 ?
用c语言编写函数,求圆的周长和面积,用函数 。急求 。。#includestdio.h
#define PI 3.1415926
double area(double r)
{
return PI * r * r;
}
double perimeter(double r)
{
return 2 * PI * r;
}
int main()
{
printf("请输入半径的值:\n");
double r;
scanf("%lf",r);
printf("周长为%lf\n",perimeter(r));
printf("面积为%lf\n",area(r));
return 0;
}
用c语言求多种图形中任何一种图形的面积 。#include stdio.h
#include math.h
double trianglearea( float a, float b, float c );
double squarearea( float a, float b );
double roundarea( float r );
int main()
{
intindex = 0;
floata, b, c, r;
double S;
while(1)
{
printf("请输入图的类型,三角形请输入1,矩形请输入2,圆形请输入3 。按0退出\n");
printf("请输入图形序号:");
scanf("%d", index);
if(index == 0)
break;
else if(index == 1)
{
printf("输入三角形三边长:");
scanf("%f %f %f", a, b, c);
S = trianglearea(a, b, c);
}
else if(index == 2)
{
printf("输入矩形的长和宽:");
scanf("%f %f", a, b);
S = squarearea(a, b);
}
else if(index == 3)
{
printf("%输入圆形的半径:");
scanf("%f", r);
S = roundarea(r);
}
else
;
printf("所求面积为%lf\n\n", S);
}
printf("\nbye bye\n");
return 0;
}
double trianglearea( float a, float b, float c )
{
double p = 0;
if( !(a bca cbb ca) )
{
printf("这三条边无法组成三角形 。\n");
return 0;
}
p = (a b c) / 2;
return sqrt(p*(p-a)*(p-b)*(p-c));
}
double squarearea( float a, float b )
{
return a*b;
【c语言编写面积函数 c语言求面积保存小数】}
double roundarea( float r )
{
return 3.14*r*r;
}
c语言.编写一个函数,用来计算圆的面积 。计算圆的面积的编程是:
#include stdio.h
#define N 3.14//圆周率
float S(float r)//计算面积
{
float s;
s=N*r*r;
return s;
}
void main()
{
float r;
printf("请输入圆的半径:");
scanf("%f",r);
printf("\n该圆的半径是:%f",S(r));
}
1、C语言的介绍:C语言是一种计算机程序设计语言,它既具有高级语言的特点,又具有汇编语言的特点 。它的应用范围广泛 , 具备很强的数据处理能力,不仅仅是在软件开发上,而且各类科研都需要用到C语言 , 适于编写系统软件,三维,二维图形和动画,具体应用比如单片机以及嵌入式系统开发 。
2、C语言的基本特性:结构式语言的显著特点是代码及数据的分隔化 , 即程序的各个部分除了必要的信息交流外彼此独立 。这种结构化方式可使程序层次清晰,便于使用、维护以及调试 。C 语言是以函数形式提供给用户的 , 这些函数可方便的调用,并具有多种循环、条件语句控制程序流向,从而使程序完全结构化 。
c语言编程 圆的面积与周长自定义函数这样:
#define pi 3.1415926
#include stdio.h
int main()
{
float r,area,perimeter;
printf("请你输入圆的半径r:\n");
scanf("%f",r);
area=pi*r*r;
perimeter=pi*r*2;
printf("直径为:%0.02f\n圆的面积为:%0.03f\n周长为:%0.02f",2*r,area,perimeter);
return 0;
}
扩展资料:
注意事项
1、常量是指在运行过程中,其值不改变的量 。
2、#define我们称为宏定义,在编译前替换,也称为预编译 。
3、宏定义,规范上用大写字母表示 。
4、float为单精度浮点型,占用4字节 , 其表示范围为10^-37到10^38 。
5、需要更长的数据表达范围和精度,还可使用双精度浮点型double,占用8字节 , 其表示范围为10^-307到10^308
用C语言编译程序:求面积#include iostream
#include iomanip// 要这个头文件
#include math.h
using namespace std;
const double PI=3.141593;
// 3 个函数:
void area(double a, double s) {
s = PI * a * a;
}
void area(double a, double b,double s) {
s = a * b;
}
void area(double a, double b, double c, double s) {
double d;
d = (a b c) / 2.0;
s = sqrt(d*(d-a)*(d-b)*(d-c)) ;
}
void showmenu()
{
coutendl"choice 1:triangle"endl;
cout"choice 2:rectangle"endl;
cout"choice 3:round"endl;
cout"choice 0:exit"endl;
cout"input your choice:"endl;
}
int main()
{int a,b,c;
char choice;
double s;
showmenu();
cinchoice;
while (choice!='0')
{switch (choice)
{case '1':cout"input the triangle's 3 side length:"endl;
cinabc;
area(a,b,c,s);
break;
case '2':cout"input the rectangle's length and width:"endl;
cinab;
area(a,b,s);
break;
case '3':cout"input the round's radius:"endl;
cina;
area(a,s);
}
cout"area=" setiosflags(ios::fixed)setprecision(2)sendl;
showmenu();
cinchoice;
}
return 0;
}
c语言编写面积函数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于c语言求面积保存小数、c语言编写面积函数的信息别忘了在本站进行查找喔 。

    推荐阅读