#include <stdio.h>
int main()
{
int a = 1, t = 2, sb;
while (a < 100)
{
int arr1[100];
a++;
t = 2;
while (t < a)
{
sb = a % t;
if (sb == 0)
{
arr1[t] = a;
for (int i = 0; i < 100; i++)
{
if (arr1[i] == arr1[t])
{
continue;
}
}
}
t++;
}
}
for (int i = 0;i<100;i++)
{
printf("合数为%d", arr1[i]);
}
return 0;
}
此时显示未定义标识符 为什么啊?
然而将
#include <stdio.h>
int main()
{
int a = 1, t = 2, sb;
while (a < 100)
{
int arr1[100];
/*a++;
t = 2;
while (t < a)
{
sb = a % t;
if (sb == 0)
{
arr1[t] = a;
for (int i = 0; i < 100; i++)
{
if (arr1[i] == arr1[t])
{
continue;
}
}
}
t++;
}
} */
for (int i = 0;i<100;i++)
{
printf("合数为%d", arr1[i]);
}
return 0;
}
中间一部分代码注释掉之后 就不再有错误提示了?
请大神帮我解答一下 谢谢!
int arr1[100]; 定义的是while循环体的局部变量,作用于仅限于while循环