C语言代码练习(第十五天)

今日练习:

37、输入连个正整数 n 和 m ,求其最大公约数和最小公倍数

38、请编程序将“China”翻译成密码,密码规律是:用原来的字母后面第4个字符代替原来的字母

39、设半径 r = 1.5,圆柱高 h = 3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。

输入连个正整数 n 和 m ,求其最大公约数和最小公倍数

运行代码

int main()
{
	int m = 0;
	int n = 0;
	int num1 = 0;
	int num2 = 0;
	int temp = 0;
	printf("请输入两个数:");
	scanf("%d %d", &num1, &num2);
	m = num1;
	n = num2;
	while (num2 != 0)
	{
		temp = num1 % num2;
		num1 = num2;
		num2 = temp;
	}
	printf("最大公约数是:%d\n", num1);
	printf("最小公倍数是:%d\n", m * n / num1);
    return 0;
}

运行结果

请编程序将“China”翻译成密码,密码规律是:用原来的字母后面第4个字符代替原来的字母

运行代码

int main()
{
	char c1 = 'C';
	char c2 = 'h';
	char c3 = 'i';
	char c4 = 'n';
	char c5 = 'a';
	printf("翻译前的密码是:%c%c%c%c%c\n", c1, c2, c3, c4, c5);
	c1 = c1 + 4;
	c2 = c2 + 4;
	c3 = c3 + 4;
	c4 = c4 + 4;
	c5 = c5 + 4;
	printf("翻译后的密码是:%c%c%c%c%c\n", c1, c2, c3, c4, c5);
	return 0;
}

运行结果

 设半径 r = 1.5,圆柱高 h = 3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。

运行代码

#define PI 3.14//宏定义Π
int main()
{
	float r = 0;
	float h = 0;
	float perimeter;
	float area;
	float sphere_Surface_Area = 0;
	float sphere_Volume = 0;
	float cylinder_Volume;
	printf("输入圆半径r,圆柱体h:");
	scanf("%f%f", &r, &h);
	perimeter = 2 * PI * r;//周长
	area = PI * r * r;//面积
	sphere_Surface_Area = 4 * PI * r * r;//圆球表面积
	sphere_Volume = 4 / 3 * PI * r * r * r;//圆球体积
	cylinder_Volume = (PI * r * r) * h;//圆柱体积
	printf("周长=%3.1f\n", perimeter);
	printf("圆面积=%3.1f\n", area);
	printf("圆球表面积=%3.1f\n", sphere_Surface_Area);
	printf("圆球体积=%3.1f\n", sphere_Volume);
	printf("圆柱体积=%3.1f\n", cylinder_Volume);
	return 0;
}

运行结果

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值