用c语言帮我写一个程序题目描述 给定两个均不超过9的正整数a和n要求编写程序求a+aa+aaa++⋯+aa⋯an个a之和。 输入 输入在一行中给出不超过9的正整数a和n。 输出 在一行中按照s = 对应的和的格式输出。
#include<stdio.h> #include<math.h>
int main() { int a, n, sum = 0, temp = 0; scanf("%d%d", &a, &n); //输入a和n for(int i = 1; i <= n; i++) //循环n次 { temp += a * pow(10, i-1); //计算aa⋯a(i个a) sum += temp; //将每次计算的结果累加到总和中 } printf("s = %d", sum); //输出结果 return 0; }
原文地址: https://www.cveoy.top/t/topic/biYd 著作权归作者所有。请勿转载和采集!