k的幂
题目描述
输入一个正整数k,输出:k k*k k*k*k……,当超过8位数时停止。
输入格式
第一行1个整数k,范围在[2,15]。
输出格式
一行,多个k的幂。
输入/输出例子1
输入:
15
输出:
15 125 3375 50625 759375 11390625
解释一下输出:
15*15=125 15*15*15=3375 .......15*15*15*15*15*15=11390625
直到大于9999999,才停止。
代码由pen pal @爱编程的小芒果(大神) 提供
下面是代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int k,x=1,ans;
bool check(ll ans)//用于判断是否超过
{
int digit=0;
while(ans!=0)
{
ans/=10;
digit++;
}
if(digit>8) return 0;
return 1;
}
int main()
{
cin>>k;
ans=k;
while(check(ans))
{
x++;
cout<<ans<<" ";
ans=pow(k,x);//pow是平方的函数
}
有用请采纳,谢谢了。