You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C语言for循环代码输出不符合预期,求正确的修正方案

问题原因

  • 你的printf语句中声明了2个%d占位符,但只传入了1个i变量,参数数量不匹配
  • 字符串内的Perulangan首字母大写,和预期的小写perulangan不符
  • 额外的前后空格、换行符位置不对,导致输出格式不符合要求

修正后的代码

#include <stdio.h>
#include <stdlib.h>

int main()
{ 
    int i;

    for(i=1; i<5; i++)
    {
        printf("    %d perulangan %d\n", i, i);
    }

    return 0;
}

修正说明

  • 给printf补充第二个i参数,匹配两个%d占位符
  • 将Perulangan修改为小写perulangan
  • 开头添加4个空格匹配预期缩进,删除多余的尾部空格,调整换行符位置,保证输出格式完全符合要求

内容的提问来源于stack exchange,提问作者andiudin andi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 16:45:04