小编Ubd*_*mad的帖子

当操作大于10位的整数时,为什么C输出乱码结果?

下面给出的代码可以使用(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)

c long-integer

0
推荐指数
1
解决办法
80
查看次数

标签 统计

c ×1

long-integer ×1