zoukankan      html  css  js  c++  java
  • 判断整数的位数

     1 #include<stdio.h>
     2 
     3 int main(void)
     4 {
     5     int x;
     6     int n = 0;
     7     
     8     scanf_s("%d", &x);
     9 
    10     x = x / 10;
    11     n++;
    12 
    13     while (x > 0)
    14     {
    15         x = x / 10;
    16         n++;
    17     }
    18 
    19     printf("%d
    ", n);
    20 
    21     return 0;
    22 }
     1 #include<stdio.h>
     2 
     3 int main(void)
     4 {
     5     int x;
     6     int n = 0;
     7 
     8     scanf_s("%d", &x);
     9 
    10     do
    11     {
    12         x = x / 10;
    13         n++;
    14     } while (x > 0);
    15 
    16     printf("%d
    ", n);
    17 
    18     return 0;
    19 }
     1 #include<stdio.h>
     2 
     3 int main(void)
     4 {
     5     int x, y =1;
     6     int n = 0;
     7 
     8     scanf_s("%d", &x);
     9 
    10     do
    11     {
    12         x = x / 10;
    13         n++;
    14     } while (x != 0);    //不等于0,继续循环
    15 
    16     printf("%d
    ", n);
    17 
    18     return 0;
    19 }
  • 相关阅读:
    while循环
    三元运算符
    switch用法
    if判断
    位运算
    逻辑运算符
    赋值运算符和比较运算符
    算术运算符
    数据类型的转换
    线程同步之(条件变量)
  • 原文地址:https://www.cnblogs.com/2018jason/p/11785294.html
Copyright © 2011-2022 走看看