Bootstrap

等比数列求和

问题及代码:
#include <stdio.h>
int main()
{
    int n,i;
    double m,q,sum;
    while(scanf("%d%lf",&n,&q)!=EOF)
    {
        sum=1;
        m=1;
        for(i=1; i<=n; i++)
        {
            m=m*q;
            sum=sum+m;
        }
        printf("%.3f\n",sum);
    }
    return 0;
}


运行结果:


;