[C++]使用循环输出图形(圆球)

话说这是某次assignment要求要的作业..
P.S: 代码不是我写的,是某个基友算出来的对应关系.

#include
using namespace std;

int main()
{
	for (int i=1; i <= 6; i++)
	{
		for (int k = 1; k <= 10 - (-i*i + 7*i -2) / 2; k++)
			cout << ' ';
		
		for (int j = 1; j <= (-i*i + 7*i -2); j++)
		{
			if((j == 1)||(j == (-i*i + 7*i -2)))
				cout << '*';
			else
				cout << ' ';
		}
		cout << endl;
	}
}

效果图:
20131106220340

[C++]10进制转换二进制(带计算过程)

某次的作业需要我们做10进制到2进制/8进制的转换为了偷懒就随手谢了下面的东西.

#include
using namespace std;

int main()
{
	const int BASE = 2;
	unsigned long num  = 0;
	
	int binaryNum[64] = {0};
	cout << "Enter a number: ";
	cin >> num;
	
	if(!cin.fail() && num > 0)
	{
		int numMod = 0, length = 0;
		while(num != 0)
		{
			numMod = num % BASE;
			binaryNum[length++] = numMod;
			cout << num << " / " <<  BASE << " = " <<
			num / BASE << " + " << numMod << endl;
			num /= BASE;
		}
		
		cout << endl  << "Length: " << length << endl;
		cout << "Result: ";
		for(int i = length-1; i >= 0; i--)
			cout << binaryNum[i];
		cout << endl;
	}
	else
		cerr << "Wrong Input.\n";
 
	return 0;
}

效果图:
20131106214952