1.Vedic square

(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.

 

 123456789
1123456789
2246813579
3369369369
4483726159
5516273849
6639639639
7753186429
8876543219
9999999999


                            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的数字根为11+0=1

21的数字根为32+1=3

48的数字根为34+8=12,1+2=3

198的数字根为91+9+8=181+8=9

注意:任何数加9的数字根还是它本身;9乘任何数字的数字根都是9

下面代码为求数字根方法

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;
}





  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值