zoukankan      html  css  js  c++  java
  • 武汉科技大学ACM:1005: 华科版C语言程序设计教程(第二版)例题5.8

    Problem Description

     老师给小豪出了一道题目:给你两个整数x和n(-10<=x<=10,1<=n<=10),让你求出x^1+x^2+x^3+……+x^n的结果。小豪现在陷入了困惑中,现在请你来帮他解决这个问题。

    Input

    输入每行两个整数x和n。

    Output

     对于每组测试数据,输出一行计算结果。

    Sample Input

    1 1
    2 2
    

    Sample Output

    1
    6
    

    HINT

     1 #include<stdio.h>
     2 
     3 
     4 long long sum(int x,int n)
     5 {
     6 long long s=0;
     7     int i,j;
     8 long long s1;
     9     for(i=1;i<=n;i++)
    10     {
    11         s1=1;
    12         for(j=1;j<=i;j++)
    13         {
    14             s1*=x;
    15         }
    16         s+=s1;
    17     }
    18     return s;
    19 }
    20 
    21 int main()
    22 {
    23     int x,n;
    24     while(scanf("%d %d",&x,&n)!=EOF)
    25     {
    26         printf("%lld
    ",sum(x,n));
    27     }
    28     
    29     return 1;
    30 }
  • 相关阅读:
    Codeforces 977F
    Codeforces 219C
    Codeforces 1132
    Codeforces 660C
    Codeforces 603A
    Codeforces 777C
    Codeforces 677
    JNUOJ 1032
    Codeforces 677D
    Codeforces 835C
  • 原文地址:https://www.cnblogs.com/liuwt365/p/4161187.html
Copyright © 2011-2022 走看看