L1-8 乘法口诀数列 (20 分)(C/C++)

在这里插入图片描述
用一个数组存放运算的结果,因为题目给出的数最大为9,随意乘积最大为81。
所以如果≥10就分成两位来存,先存十位再存个位。小于10就直接存在下一个里面。

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include <algorithm>
#include<string.h>
#include<math.h>
#define llu unsigned long long
using namespace std;

int main()
{
	//cout << fixed << setprecision(0);
	//cout << setw(8) << setiosflags(ios::left);
	int a[2000],n;
	cin >> a[0] >> a[1] >> n;
	//cout << a1 << " " << a2 ;
	
	int s=2;
	for(int i=2;i<=n;i++)
	{
		int t=a[i-2]*a[i-1];
		//cout << t << " " ;
		if(t>=10){
			a[s++]=t/10;
			a[s++]=t%10;
		}
		else a[s++]=t;
	}
	
	cout << a[0] ;
	for(int i=1;i<n;i++)
	{
		cout << " " << a[i] ;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值