L1-8 乘法口诀数列 (20 分)(C/C++)
  9zolsZ0v5GjU 2023年11月18日 62 0

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

用一个数组存放运算的结果,因为题目给出的数最大为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] ;
	}
}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月18日 0

暂无评论

推荐阅读
  anLrwkgbyYZS   2023年12月30日   28   0   0 i++iosi++ioscici
9zolsZ0v5GjU