求整数的位数

| October 19, 2007 13:42 | timmy | Via Original
输入一个正整数repeat (0输入一个整数,输出它的位数。
例:括号内是说明
输入
4   (repeat=4)
123456  -100  -1   99
输出
count=6 (123456的位数是6)
count=3 (-100的位数是3)
count=1 (-1的位数是1)
count=2 (99的位数是2)


#include <stdio.h>
int main( )
{
  int ri, repeat;
  int count;
  long in;

  scanf("%d", &repeat);
  for(ri=1; ri<=repeat; ri++){
    scanf("%ld", &in);
  count=0;
  if(in<0)
    in=-in;
  do{
    in=in/10;
    count++;
  }while(in!=0);
    printf("count=%d\n", count);
  }
}
Tags:
Program/Code » C/C++ | Comments(0) | Trackbacks(0) | Reads(405)
Add a comment
 Site URI
 Email
  Password Optional
 Nickname  *  [Register]
               

 
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Remember