当前位置:网站首页>C语言刷题随记 —— 求 s=a+aa+aaa+aaaa+aa...a 的值
C语言刷题随记 —— 求 s=a+aa+aaa+aaaa+aa...a 的值
2022-06-21 17:28:00 【繁依Fanyi】

题目
计算 s = a + aa + aaa + aaaa +…+ aa…a 的值。
其中 a 是一个数字。
例如 2+22+222+2222+22222(此时共有 5 个数相加),几个数相加由键盘控制。
思路
利用循环语句计算出每一项都值并相加。
题解
#include <stdio.h>
int main()
{
int a,n,count=1;
long int sn=0,tn=0;
printf("请输入 a 和 n:");
scanf("%d %d",&a,&n);
while(count<=n)
{
tn=tn+a;
sn=sn+tn;
a=a*10;
++count;
}
printf("s=%ld\n",sn);
}
样例输出



边栏推荐
- Six steps of JDBC programming
- R language bug? report errors? As for the outcome of sub variables 0 and 1, the original content of the outcome variable is changed through the process of factor and numeric?
- VsCode自定义模板,用模板记笔记?!
- 剑指Offer 57. 二叉树的下一个节点
- [HCTF 2018]WarmUp
- Day16QtQLabel2021-10-22
- Typescript compilation generation file comparison
- Servlet learning (II)
- C语言__attribute__(packed)属性(学习一下)
- JDBC notes
猜你喜欢
随机推荐
JDBC Basics
Servlet学习(二)
图像分类、AI 与全自动性能测试
I/0多路转接之select
【艾思软件】微信小程序开发报价方案模版
Disclose the design idea of MVVM framework supporting Baidu search, feed and applet, and San core personnel have made great efforts to build it
Six steps of JDBC programming
Day19QPushButton的使用2021-10-30
【Go语言】Go语言我们应该这样学~全网较全的学习教程
Product graphic list description layout style
Character processing of node
EL表达式
Canvas sphere particle changing color JS special effect
中国两颗风云气象“新星”主要数据产品将向全球用户开放共享
Canvas动态网状背景js特效
Day12QFile2021-09-27
新赛季的中超和国安,荆棘中前行
Day13QMainWindow2021-09-28
Servlet specification (I)
Cookies and sessions









