烟火的你 2021-05-08 00:05 采纳率: 100%
浏览 20
已采纳

老哥懂行吗?运行出问题,得不到想要的结果。

老哥懂行吗?运行出问题,得不到想要的结果。
  • 写回答

4条回答 默认 最新

  • benbenli 2021-05-08 02:04
    关注

    哦,题目要求些一个函数。下面代码写了一个函数,而且不限于4位数。

    #include <stdio.h>
    
    char* digits(int number, char* buffer, int size)
    {
        char* p = buffer + (size - 1);
        *p = 0; // end of string
        
        if (number == 0)
        {
            *(--p) = '0';
        }
        else
        {
            while (number > 0)
            {
                int d = number % 10;
                number /= 10;
                if (*p != 0)
                    *(--p) = ' ';
                *(--p) = '0' + d;
            }        
        }
    
        return p;
    }
    
    int main()
    {
        int n;
        char s[100];
        
        printf("Please enter a 4-digit number:");
        scanf("%d", &n);
        
        char* p = digits(n, s, 100);
        
        printf("The digits of the number are: %s\n", p);
    }
    
    // Output
    Please enter a 4-digit number:1990                                                                                                                                                 
    The digits of the number are: 1 9 9 0
    
    Please enter a 4-digit number:31415926                                                                                                                                             
    The digits of the number are: 3 1 4 1 5 9 2 6    

    附注:求赞助积分和C币。加入CSDN将近20年了。最近几年忙小孩没登录。刚才搜索到一本电子书想下载,需要20积分/C币。已经收到8元了,还查12元。赞助多少都可以。多谢。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.