C 语言实例 - 判断数字为几位数

C 语言教程 · 2019-02-20 19:58:29

用户输入数字,判断该数字是几位数。

实例

#include <stdio.h> int main() { long long n; int count = 0; printf("输入一个整数: "); scanf("%lld", &n); while(n != 0) { // n = n/10 n /= 10; ++count; } printf("数字是 %d 位数。", count); }

运行结果:

输入一个整数: 2345
数字是 4 位数。

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

查看所有标签

The Effective Engineer

The Effective Engineer

Edmond Lau / The Effective Bookshelf, Palo Alto, CA. / 2015-3-19 / USD 39.00

Introducing The Effective Engineer — the only book designed specifically for today's software engineers, based on extensive interviews with engineering leaders at top tech companies, and packed with h......一起来看看 《The Effective Engineer》 这本书的介绍吧!

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

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具