当i不等于n的时候在s字符串最后加上一个“+”号,当输出最后一个字符串,比如22222时候i=5,n=5,这个时候不要再s最后加上“+”号
如果有这句,比如a=2,n=5时候输出是这样的:
当a=2时,n=5时,s=2+22+222+2222+22222
如果没有这句if
i
<>
n
then
s
=
s
+
"+"
那么输出是这样的:
当a=2时,n=5时,s=222222222222222
或者没有判断语句,只有s=s
+
"+"
那么输出是这样的:
当a=2时,n=5时,s=2+22+222+2222+22222+
:
#include
using namespace std;
int main()
{
int n,a;
cin>>n;
cin>>a;
int s=0,i,t=a;
for(i=1;i<=n;i++){
s+=t;
t=t*10+a;
}
cout < return 0;
}
#include
using namespace std;
int main()
{
int a , N;
cout <<"Please input the 'N' :" <
cout <<"Please input the 'a' :" <
int s=0,i,t=a;
for(i = 1; i <= N; i++)
{
s += t;
t = t*10 + a;
}
cout << "The results is "<< s <
}
#include
using namespace std;
int main()
{
int a = 1, N;
unsigned int s = 0;
cout <<"Please input the "N" :" <
for(int i = 0; i < N; i++)
{
s = s + a;
a = a*10 + a;
}
cout << "The results is "<< s <
}
#include
#include
int main() {
int a=3, n=3, sum = 0, s= 0;
int i,j;
for(i = 0; i< n; i++) {
sum += (int) pow(10, i) * a + s;
s+= (int)pow(10, i) * a;
}
printf("%d\n", sum);
return 0;
}