C语言——球体体积&判断素数&用递归计算Fibonacci数列

1.编写求圆球体体积的函数(体积V=4/3*π*R3),在主函数里输入球体半径R(使用Scanf()函数通过键盘输入)并调用该函数显示当R=3时球体体积。#include<stdio.h>#include<math.h>#define pi 3.1415926double sphere_volume(double n){ return (4/3.0)*pi*...
摘要由CSDN通过智能技术生成

1.编写求圆球体体积的函数(体积V=4/3*π*R3),在主函数里输入球体半径R(使用Scanf()函数通过键盘输入)并调用该函数显示当R=3时球体体积。

#include<stdio.h>
#include<math.h>
#define pi 3.1415926
double sphere_volume(double n)
{
	return (4/3.0)*pi*pow(n,3);
}
void main()
{
	double V,R;
	printf("input radius :");
	scanf("%lf",&R);
	V=sphere_volume(R);
	printf("the sphere's volume is %.2f",V);
}

2.编写自定义函数(prime函数):功能是判断任意一个整型数是否是素数。通过主函数main函数调用判断m是否是素数。(m通过键盘输入)

附加题:main函数功能:通过键盘输入一个正整数m,调用prime函数统计[2-m]之间的所有素数的个数。

 

#include<stdio.h>
#include<math.h>
void main()
{
	int m;
	int prime(int m);
	printf("input a number:");
	scanf("%d",&m);
	if(prime(m)==1)
		printf("the number is prime number!\n");
	else
		printf("sorry,the number is not prime number!\n");
}
int
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值