如何在C中按如下方式打印图案? #1234567 1#345678 23#56789 345#7890 4567#901 56789#12 678901#3 7890123#

如何在C中按如下方式打印图案? #1234567 1#345678 23#56789 345#7890 4567#901 56789#12 678901#3 7890123#,c,C,这是我的密码 int main() { int pattern; int rows, columns; printf("Enter the pattern: "); scanf("%d", & pattern); for (rows = 1; rows <= pattern; rows++) { for (columns = 1; columns <= pattern; columns++) {

这是我的密码

int main() {
    int pattern;
    int rows, columns;

    printf("Enter the pattern: ");
    scanf("%d", & pattern);

    for (rows = 1; rows <= pattern; rows++) {
        for (columns = 1; columns <= pattern; columns++) {
            if (rows == columns)
                printf("#");
            else
                printf("%d", columns);
        }
        printf("\n");
    }

    return 0;
}
intmain(){
int模式;
int行、列;
printf(“输入模式:”);
scanf(“%d”、&pattern);

对于(rows=1;rows从0到pattern-1启动内部和外部循环。打印
(列+行)%10
。您的工作将完成。请参阅下面代码中的更改:

int main() {
    int pattern;
    int rows, columns;

    printf("Enter the pattern: ");
    scanf("%d", & pattern);

    for (rows = 0; rows < pattern; rows++) {
        for (columns = 0; columns < pattern; columns++) {
            if (rows == columns)
                printf("#");
            else
                printf("%d", (columns+rows)%10);
        }
        printf("\n");
    }

    return 0;
}
intmain(){
int模式;
int行、列;
printf(“输入模式:”);
scanf(“%d”、&pattern);
对于(行=0;行<模式;行++){
对于(列=0;列<模式;列++){
如果(行==列)
printf(“#”);
其他的
printf(“%d”,(列+行)%10);
}
printf(“\n”);
}
返回0;
}

下一步是查看程序的输出,看看它与预期的输出有何不同。另外,程序的输入是什么?您好,欢迎使用StackOverflow。请编辑您的问题,将您得到的输出包括在内。谢谢。是否可以不使用其他变量?谢谢。当然可以。可以通过写入(列+行)%10)而不是(列+增量)%10)。无需添加其他变量。我会相应地编辑我的答案。请看,希望它能帮助您。