(1)Problem Description
In ancient Indian mathematics, a Vedic square is a variation on a typical 9×9multiplication table. The entry in each cell is the digital root of the product of thecolumn and row headings.
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
2 | 2 | 4 | 6 | 8 | 1 | 3 | 5 | 7 | 9 |
3 | 3 | 6 | 9 | 3 | 6 | 9 | 3 | 6 | 9 |
4 | 4 | 8 | 3 | 7 | 2 | 6 | 1 | 5 | 9 |
5 | 5 | 1 | 6 | 2 | 7 | 3 | 8 | 4 | 9 |
6 | 6 | 3 | 9 | 6 | 3 | 9 | 6 | 3 | 9 |
7 | 7 | 5 | 3 | 1 | 8 | 6 | 4 | 2 | 9 |
8 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 9 |
9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 |
By replacing a specific number by asterisk whereas the others by space within theVedic square, you can find some distinct shapes each with some form of reflectionsymmetry.
You are to print the Vedic square first, and then the shapes of every specific 2number. An example of the shape of number 1 is as follows.
这道题的意思就是说在 9×9 的表中(与九九乘法表类似),只是表的每个格不是行列序号的乘积,而是乘积的数字根。
输入一个数字 , 与数字一样的数字根用*表示
数字根:
定义
数字根(Digital Root)就是把一个数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止。而这个一位数便是原来数字的数字根。适用范围为正整数和零。例如:
1的数字根为1
10的数字根为1(1+0=1)
21的数字根为3(2+1=3)
48的数字根为3(4+8=12,1+2=3)
198的数字根为9(1+9+8=18,1+8=9
下面代码为求数字根方法
int fun(int a) //定义函数
{
if (a <10)
return a;
int t = 0;
while (a)
{
t += a % 10;
a /= 10;
}
return fun(t);
}
源代码如下:
int fun(int a) //定义函数
{
if (a <10)
return a;
int t = 0;
while (a)
{
t += a % 10;
a /= 10;
}
return fun(t);
}
#include<iostream>
using namespace std;
int fun(int a) //定义函数
{
if (a <10)
return a;
int t = 0;
while (a)
{
t += a % 10;
a /= 10;
}
return fun(t);
}
int main()
{
int i, j, t=0,m,n=1;
int a;
int b; //所输入图形数字根
cout << "\t";
for (m = 1; m <= 9; m++)
cout << m << "\t";
cout << endl;
for(i=1;i<=9;i++)
for (j = 1; j <= 9; j++,t++)
{
a = i*j;
if (t % 9 == 0)
{
cout << endl;
cout << n++ << "\t";
}
cout << fun(a)<<"\t"; //函数调用
}
n = 1;
t = 0;
cout << endl;
cout << "Please input a number" << endl;
cin >> b;
cout << "\t";
for (m = 1; m <= 9; m++)
cout << m << "\t";
cout << endl;
for (i = 1; i <= 9; i++)
for (j = 1; j <= 9; j++, t++)
{
a = i*j;
if (t % 9 == 0)
{
cout << endl;
cout << n++ << "\t";
}
if(b==fun(a))
cout << "*" << "\t";
if (b != fun(a)) {
cout << " " << "\t";
}
}
cout << endl;
return 0;
}