#include
int pow(int a,int n);
void main()
{
int a,n;
register int s=0,i;
printf("输入底数a\n");
scanf("%d",&a);
printf("输入指数n\n");
scanf("%d",&n);
for(i=n;i>0;i--) s=s+pow(a,i);
printf("%d^1+%d^2+.......+%d^%d=%d\n",a,a,a,n,s);
}
int pow(int a,int n)
{
register int c=1;
for(;n>0;n--) c=c*a;
return c;
}
#include "stdio.h"
#include "math.h"
void main()
{
register x,n,sum,i;
printf("input x:");
scanf("%d",&x);
printf("input n:");
scanf("%d",&n);
for(i=1,sum=0;i<=n;i++)
sum+=pow(x,i);
printf("output :%d",sum);
}
#include
#include
void main()
{ redister x,n,sum=0,k; //定义寄存器变量
printf("please input a X");
scanf("%d",&x);
printf("please input a N");
scanf("%d",&n);
for(i=1;i<=n;i++) //循环
sum=sum+pow(x,i);
printf("sum=%d",sum);
}
#include "stdio.h"
#include "math.h"
void main()
{
register x,n,sum,icount;
printf("input x:");
scanf("%d",&x);
printf("input n:");
scanf("%d",&n);
icount=1-pow(x,n);
sum = icount/(1-x);
printf("output :%d",sum);
}
//没使用循环,效率高,速度快