#include<iostream.h>
void main(){
int a;
int n;
int sum=0;
int d=0;
int c=1;
cout<<"please input a:";
cin>>a;
cout<<"please input n:";
cin>>n;
for(int j=1;j<=n;j++)
{
for(int i=1;i<=j;i++)
{
sum=sum+a*c;
c=c*10;
}
sum=d+sum;
c=1;
d=0;
}
cout<<sum<<endl;
}
用C++编的,测试过应该对吧!
void main(){
int a;
int n;
int sum=0;
int d=0;
int c=1;
cout<<"please input a:";
cin>>a;
cout<<"please input n:";
cin>>n;
for(int j=1;j<=n;j++)
{
for(int i=1;i<=j;i++)
{
sum=sum+a*c;
c=c*10;
}
sum=d+sum;
c=1;
d=0;
}
cout<<sum<<endl;
}
用C++编的,测试过应该对吧!