C++

C++实验(一):数根表

Posted by HK on March 14, 2019

整理一些做过的实验题。

Vedic Square and Vedic Star

(1)Problem Description

In ancient Indian mathematics, a Vedic square is a variation on a typical 9×9 multiplication table. The entry in each cell is the digital root of the product of the column and row headings. Vedic Square是一个9×9的表,与九九乘法表类似。只是表的每个格不是行列序号的乘积,而是乘积的数字根。下图是Vedic Square。

等待网络加载图片···

(2)Vedic Star

By replacing a specific number by asterisk whereas the others by space within the Vedic square, you can find some distinct shapes each with some form of reflection symmetry.

(3)Output

You are to print the Vedic square first, and then the shapes of every specific number. An example of the shape of number 1 is as follows.

等待网络加载图片··· 等待网络加载图片··· 等待网络加载图片···

#include<iostream>
using namespace std;

void menu();
void printsquare(int a[9][9]);

int main()
{
	int n,i,j;
	int a[9][9];
	printsquare(a);
	cout << "请输入1-9之间任意一个数字:(输入0退出)\n";
	cin >> n;
	while(n!=0)
	{
		for (i = 0; i < 9; i++)
		{
			for (j = 0; j < 9; j++)
			{
				if (a[i][j] == n) cout << "  *";
				else cout << "   ";
			}
			cout << "\n";
		}
		cout << "请输入1-9之间任意一个数字:(输入0退出)\n";
		cin >> n;
	} 
	return 0;
}

void printsquare(int a[9][9])
{
	int i, j;
	cout << "   |  1  2  3  4  5  6  7  8  9  " << endl;
	cout << "---|---------------------------" << endl;
	for (i = 0; i < 9; i++)
	{
		cout << " " << i << " |";
		for (j = 0; j < 9; j++)
		{
			a[i][j] = ((i + 1)*(j + 1)) % 9;
			if (a[i][j] == 0) a[i][j] = 9;
			cout << "  " << a[i][j];
		}
		cout << "\n";
	}
	cout << "\n";
}