jwbf.net
当前位置:首页 >> C语言定义两个宏分别求圆的周长和面积 >>

C语言定义两个宏分别求圆的周长和面积

下载文件:1021113.zip

#include "stdio.h" #define Pi 3.1415926 double zhouchang(double r) { double s; s=2*Pi*r; return s; } double mianji(double r) { double s; s=Pi*r*r; return s; } int main() { double r,m,n; printf("请输入圆的半径:"); scanf("%lf",&r...

一、数学公式: 圆周长=2*π*半径 面积=π*半径² 二、算法分析: 周长和面积都依赖半径,所以要先输入半径值,然后套用公式,计算周长和面积。 最终输出结果即可。 三、参考代码: #include #define PI 3.14159int main(){ double r, s, c; s...

#include#define Pi 3.14159double Square(double r){ return Pi * r * r;}double Perimeter(double r){ return 2 * Pi * r;}int main(){ double r; printf("请输入圆的半径:\n"); while(scanf("%lf",&r)!= EOF){ printf("圆的面积是%lf\n",Squ...

#include #define pi 3.1415926 void main() { float r,l,s; printf("请输入圆的半径:"); scanf("%f",&r); l=2*pi*r; s=pi*r*r; printf("圆的周长为:%f\n,圆的面积为:%f\n",l,s); }

# include #define PI 3.1415926 using namespace std; void a() { double r,c,s; coutr; c=PI*r*2; s=PI*r*r; cout

void print(double r){ if (r 0 else printf("S = %lf, C = %lf\n", 3.14*r*r, 2*3.14*r);}

#include "stdio.h"int main(void){ double r=10.0,pi=3.1415926; printf("The girth was %g\nThe area was %g\n",2*pi*r,pi*r*r); return 0;}

方法如下: #include "stdio.h" #define Pi 3.14 void main() { float r,c,area; printf("请输入圆的半径:"); scanf("%f",&r); c=2*Pi*r; area=Pi*r*r; printf("该圆的周长是%.2f,面积是%.2f\n",c,area); }

#include void main() { float r; printf("请输入圆的半径: "); scanf("%f",&r); printf("圆的周长是: %f\n",(2*3.14*r));//求出圆周长 printf("圆的面积是: %f\n",(3.14*r*r));//求出圆面积 }

网站首页 | 网站地图
All rights reserved Powered by www.jwbf.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com