加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

求x^k的值

发布时间:2020-12-14 01:29:14 所属栏目:大数据 来源:网络整理
导读:求x^k的值: #includestdio.h#includestring.h#includestdlib.h#includemath.h#includealgorithmusing namespace std;char s[100],s1[100];int main(){ int m,x,k; scanf("%d",m); while(m--) { int i; scanf("%d",x); scanf("%d",k); memset(s,0x00,sizeof(

求x^k的值:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;

char s[100],s1[100];
int main()
{
  int m,x,k;
  scanf("%d",&m);
  while(m--)
  {
    int i;
    scanf("%d",&x);
    scanf("%d",&k);
    memset(s,0x00,sizeof(char)*100);  //memset(s,'0',sizeof(s));
    strcpy(s,"1");
    int carry=0;
    for(i=1;i<=k;i++)
    {
      int len=strlen(s),j;
//    printf("%d",len);
      for( j=0;j<len;j++)
      {
        int res=(s[j]-'0')*x+carry;
        carry=res/10;
        s[j]=(res%10)+'0';
      }

      while(carry!=0)
      {
        s[j++]=(carry%10)+'0';
        carry/=10;

      }
    }
    reverse(s,s+strlen(s));
    printf("%sn",s);
  }
  return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读