#include <sdio.h>
int main(void)
for (int k = 1, k <19, k++); {
printf("%d*%d=%d n", k, k, k * k);
return 0;
}
我刚开始学习C,就面临着这个问题。如果可以的话,还可以向我推荐初学者的好指南。:(
问题在这一行:
for (int k = 1, k <19, k++);
在for语句中,应该用分号(;
(分隔元素
for (int k = 1; k <19; k++)
在它的末尾也没有(;
(
此外,应该包括<stdio.h>
而不是<sdio.h>
。
您的代码包含多个语法错误和多个逻辑错误。原始版本的格式非常糟糕,几乎无法被人类阅读。
你想要这个:
#include <stdio.h>
int main(void)
{
for (int k = 1; k < 19; k++)
{
printf("%d*%d=%d n", k, k, k * k);
}
return 0;
}
您的原始代码已重新格式化并带有注释:
#include <sdio.h>
int main(void)
// { missing here
for (int k = 1, k <19, k++); { // the final ; should not be here
// ^ ^ use ; instead of ,
printf("%d*%d=%d n", k, k, k * k);
return 0; // should not be in the loop but after the loop
}
// } missing here