提供一个C的作参考:
#include "stdio.h"
int main(void){
搏改 int n,i,t;
double sum;
while(1){
printf("Input n(int n>0)...\nn=");
穗饥if(scanf("%d",&n) && n>0)
猜银返 break;
printf("Error, redo: ");
}
for(n<<=1,sum=t=0,i=1;iprintf("The result is %f\n",sum);
return 0;
}