C 练习实例18

C 语言教程 · 2019-02-21 16:28:05

题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。

程序分析:关键是计算出每一项的值。

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include<stdio.h> int main() { int s=0,a,n,t; printf("请输入 a 和 n:\n"); scanf("%d%d",&a,&n); t=a; while(n>0) { s+=t; a=a*10; t+=a; n--; } printf("a+aa+...=%d\n",s); return 0; }

以上实例输出结果为:

请输入 a 和 n:
2 5
a+aa+...=24690

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

Database Design and Implementation

Database Design and Implementation

Edward Sciore / Wiley / 2008-10-24 / 1261.00 元

* Covering the traditional database system concepts from a systems perspective, this book addresses the functionality that database systems provide as well as what algorithms and design decisions will......一起来看看 《Database Design and Implementation》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具