001、方法1
while循环
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c ## 测试c程序 #include <stdio.h> int get_length(int a) { int length = 0; while(a > 0) { length++; a /= 10; } return length; } int main(void) { int a; printf("a = "); scanf("%d", &a); printf("the length of %d is %d\n", a, get_length(a)); return 0; } [root@PC1 test]# gcc test.c -o kkk ## 编译 [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk a = 3456 the length of 3456 is 4 [root@PC1 test]# ./kkk a = 34 the length of 34 is 2 [root@PC1 test]# ./kkk a = 354676 the length of 354676 is 6 [root@PC1 test]# ./kkk a = 6 the length of 6 is 1
。
002、do...while
标签:返回,int,PC1,整数,length,kkk,test,长度,root From: https://www.cnblogs.com/liujiaxin2018/p/18536093