今日练习:
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;
}