除位法
#include<stdio.h>main()
{
int n,k=0
scanf("%d",&n)
while(n)
{
n/=10
k++
}
printf("%d",k)
}
对数法
#include<stdio.h>#include<math.h>
main()
{
int n,k
scanf("%d",&n)
k=log(n)/log(10)+1
printf("%d",k)
}
char型数组法
#include<stdio.h>#include<math.h>
main()
{
char n[100],k
gets(n)
for(k=0n[k]k++)
printf("%d",k)
}
数组转换法
#include<stdio.h>#include<string.h>
main()
{
char str[20]
int n
scanf("%d",&n)
sprintf(str,"%d",n)
printf("%d\n",strlen(str))
}
您好,很高兴为您解答,流星不死为您答疑解惑
如果本题还有不懂的地方请追问,望采纳我的回答。
祝楼主学习进步。
上面的代码可以直接复制到编译器里,带换行。
1、在c语言中定义bit型变量,可以使用位域来自定义。
位域的定义和位域变量的说明位域定义与结构定义相仿,其形式为:
struct 位域结构名
{ 位域列表 }
其中位域列表的形式为: 类型说明符 位域名:位域长度
2、示例:通过位域来计算IEEE754浮点数标准中,单精度浮点数的最大值、最小值以及最小弱规范数。
#include <stdio.h>typedef struct FP_SINGLE
{
unsigned __int32 fraction : 23
unsigned __int32 exp : 8
unsigned __int32 sign : 1
} fp_single
int main()
{
float x
fp_single * fp_s = (fp_single *)&x
fp_s->sign = 0
fp_s->exp = 0xfe
fp_s->fraction = 0x7fffff
printf ("float 最大数: %le\n",(double)x)
fp_s->sign = 0
fp_s->exp = 0x1
fp_s->fraction = 0x0
printf ("float 最小数: %le\n",(double)x)
fp_s->sign = 0
fp_s->exp = 0
fp_s->fraction = 0x1
printf ("float 最小弱规范数:%le\n\n",(double)x)
return 0
}