下面给出的代码可以使用(int数据类型)精确到10位数,但是对于超过10位的数字,它失败了,所以我尝试了unsigned long long int.但现在我的输出固定为15,idk为什么?考虑我对C非常新,但我有平庸的python背景!
我正在使用gcc(Ubuntu 5.4.0-6ubuntu1~16.04.1)5.4.0 20160609
#include <stdio.h> //Get number of digits in a int
unsigned long long int get_len();
void main() {
unsigned long long int num;
printf("Enter the number:");
scanf("%d",&num);
printf("\nThe length of number is is: %d \n",get_len(num));
}
unsigned long long int get_len(unsigned long long int z) {
unsigned long long int i = 1;
while (1) {
if ((z/10) > 1) {
//printf("Still greater than 1");
i++;
z = z/10;
continue;} …Run Code Online (Sandbox Code Playgroud)