S=2+22+222+...n个2的值..
求S=2+22+222+...n个2之值的算法..#include<stdio.h>
#include<math.h>
void main()
{
double m,n,i,sum;
printf("please input number n:\n");
scanf("%d",&n);
if(n==1) sum=2;
else if(n>=2)
for (m=2,sum=2,i=2;i<=n;i++)
{
m=m+2*pow(10,(i-1));
sum=sum+m;
}
printf("%d",sum);
}
刚学习C自己想的,大家都来帮忙看下对不???