团体程序设计天梯赛-练习集 L1-002 打印沙漏(C++)

这篇博客详细介绍了如何使用C++编程语言来实现打印沙漏图案的算法,包括其逻辑步骤和代码实现,适合初学者提升编程技能。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <cmath>
//We will use sqrt function.


//原理:输入数字和符号;经过计算后,给出多余数字和最外层字符显示数;利用最外层字符显示数逐行输出,显示多余数字。
//The core princple: First, we import the number and the character; and after calculating, we can get 
//the redundance value (acronym: RedunVal) and the number of characters of the first row
//(acronym: FirRowCharNum); Finally, we utilize FirRowCharNum to display characters row by row and RedunVal.


//输入函数 The input function of two data
void input2(int& num, char& ch) {
	std::cin >> num;
	std::cin >> ch;
}
//计算函数 The calculating function: the result is the change of RedunVal and FirRowCharNum.
void calculating(int num,int& RedunVal, int& FirRowCharNum) {
	//数字逐个减去一,2*三,2*五,2*七……,直到它变成负数,知道RedunVal是多少了
	//Subtract 1,2*3,2*5,2*7... from num succesively until the difference is negatice,
	//then we can get RedunVal.
	//倒数第二个充当减数的奇数,就是FirR
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值