输入正整数a,n输出a+aa+aaa+…的和
时间: 2023-11-12 11:04:53 浏览: 72
正整数a和n,求a+aa+aaa+…的和,其中有n个数相加,每个数都是a的连续相乘,例如a=5,n=3时,5+55+555=615。
```python
# Python代码示例
a = int(input("请输入a的值:"))
n = int(input("请输入n的值:"))
sum = 0
for i in range(n):
sum += a * (10 ** i) * n
print("a+aa+aaa+...的和为:", sum)
```
相关问题
输入正整数a,n输出a+aa+aaa+…的和c语言
是输入正整数a,n输出a+aa+aaa+…的和的C语言代码:
```c
#include <stdio.h>
#include <math.h>
int main() {
int a, n, sum = 0, term = 0;
printf("请输入正整数a和n的值:\n");
scanf("%d %d", &a, &n);
for (int i = 1; i <= n; i++) {
term = term * 10 + a;
sum += term;
}
printf("a+aa+aaa+...的和为:%d\n", sum);
return 0;
}
```
键盘输入正整数+a+和+n+,+编程+ss=a+aa+aaa+aaa+a.+a+(+n+个+a+)+的值。
以下是Java语言的代码实现,可以实现键盘输入正整数a和n,然后计算出ss=a+aa+aaa+...+a(n个a)的值:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入正整数a:");
int a = scanner.nextInt();
System.out.print("请输入正整数n:");
int n = scanner.nextInt();
int sum = 0;
int temp = a;
for (int i = 1; i <= n; i++) {
sum += temp;
temp = temp * 10 + a;
}
System.out.println("ss=a+aa+aaa+...+a(n个a)的值为:" + sum);
}
}
```
阅读全文