楼主的意思是要输入N,比如N=1,那么输出这样的效果吧
1+11+111+1111+11111+111111+1111111+11111111+111111111=123456789
程序代码:
root@~ #cat 1.c
#include <stdio.h>
int main (void) {
int i,j=1,n;
long int s1=0,s2=0;
printf ("Enter number:");
scanf ("%i",&n);
for(i=1;i<10;i++,j*=10) {
s1+=n*j;
s2+=s1;
printf ("%li+",s1);
}
printf ("\b=%li\n",s2);
return 0;
}
root@~ #./1
Enter number:1
1+11+111+1111+11111+111111+1111111+11111111+111111111=123456789
root@~ #./9
bash: ./9: No such file or directory
root@~ #./1
Enter number:9
9+99+999+9999+99999+999999+9999999+99999999+999999999=1111111101
root@~ #
[
本帖最后由 ansic 于 2011-3-30 18:08 编辑 ]