Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C不能只循环一次_C_Loops - Fatal编程技术网

C不能只循环一次

C不能只循环一次,c,loops,C,Loops,代码如下: #include <stdio.h> #define ROWS 6 #define CHARS 10 int main(void) { int row; char ch; for(row = 0; row < ROWS; row++) { printf("%d\n", row); for(ch = 'A'; ch

代码如下:

    #include <stdio.h>
    #define ROWS 6
    #define CHARS 10
    int main(void)
    {
        int row;
        char ch;

        for(row = 0; row < ROWS; row++)
        {
            printf("%d\n", row);
            for(ch = 'A'; ch < ('A' + CHARS); ch++)
                printf("%c", ch);
            printf('\n');
        }
        getchar();
        return 0;
    }
我认为输出类似于这样:

0
ABCDEF
1
ABCDEF
2
ABCDEF
3
ABCDEF
4
ABCDEF
5
ABCDEF
问题是为什么只循环一次。

“ABCDEF”
包含6个字符,所以您需要更改

#define CHARS 10

另外,
printf
接受一个字符串,因此您应该使用
“\n”
而不是
“\n”

#include <stdio.h>
#define ROWS 6
#define CHARS 6 
int main(void)
{
    int row;
    char ch;

    for(row = 0; row < ROWS; row++)
    {
        printf("%d\n", row);
        for(ch = 'A'; ch < ('A' + CHARS); ch++)
            printf("%c", ch);
        printf("\n"); // Should use double quotes here
    }
    getchar();
    return 0;
}
#包括
#定义第6行
#定义字符6
内部主(空)
{
int行;
char ch;
对于(行=0;行<行;行++)
{
printf(“%d\n”,行);
for(ch='A';ch<('A'+字符);ch++)
printf(“%c”,ch);
printf(“\n”);//此处应使用双引号
}
getchar();
返回0;
}

问题是??谢谢,我需要一个地方来思考我的余生。@当然,没问题。如果有帮助,你应该接受答案。
#define CHARS 6
#include <stdio.h>
#define ROWS 6
#define CHARS 6 
int main(void)
{
    int row;
    char ch;

    for(row = 0; row < ROWS; row++)
    {
        printf("%d\n", row);
        for(ch = 'A'; ch < ('A' + CHARS); ch++)
            printf("%c", ch);
        printf("\n"); // Should use double quotes here
    }
    getchar();
    return 0;
}