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

今日练习:

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

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

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

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

运行代码

cpp 复制代码
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个字符代替原来的字母

运行代码

cpp 复制代码
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,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。

运行代码

cpp 复制代码
#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;
}

运行结果

相关推荐
Navigator_Z5 小时前
LeetCode //C - 1288. Remove Covered Intervals
c语言·算法·leetcode
铅笔小新z7 小时前
【C语言】深入理解指针
c语言·开发语言
Aurorar0rua13 小时前
CS50 x 2024 Notes Data structures - 08
c语言·开发语言·学习方法
小米里的大麦14 小时前
19 C、C++ 操作 MySQL
c语言·c++·mysql
Logic10114 小时前
C语言/数据结构位运算题解:异或XOR找出套碗游戏中的“幸运碗“——只出现一次的数字
c语言·数据结构·算法·数组·位运算·时间复杂度·空间复杂度
番茄灭世神14 小时前
PN学堂GD32教程第12篇——SPI与Nor Flash
c语言·stm32·单片机·嵌入式·gd32·总线协议
苏辰澈15 小时前
C++独属于自己的变身:多态
c语言·开发语言·c++·visualstudio·编辑器
水饺编程15 小时前
第1章,[Win32 章节]:在 VS2019 里面安装 MSDN
c语言·c++·windows·visual studio
水饺编程15 小时前
第1章,[Win32 章节]:编程环境与 MSDN
c语言·c++·windows·visual studio
wuminyu1 天前
ForkJoinPool窃取线程在扫描其他WorkQueue时的随机采样算法与Phase线程挂起唤醒机制解析
java·linux·c语言·jvm·c++