C语言 while语句

for语句跟while语句差不多,如果题目中指定了循环次数,用for更清晰,循环的四个组成一目了然;其他条件下多使用while语句

#include <stdio.h>
int main()
{
    int x;
    int n=0;
    scanf("%d",&x);
    while(x>0) {n++; x/=10;}
    printf("%d\n",n);
    return 0;
}

这是一个判断输入的数共有几位的程序。

猜你喜欢

转载自www.cnblogs.com/httpwwwachangcom/p/9454373.html