0
难以置信的新编程我收到第12行的错误,指出我的break语句不在循环或开关中。任何人都可以解释我的错误在哪里以及如何解决它?为什么我在我的“for”循环中收到错误,说'break'语句不在循环或开关中?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int n1, n2, i, gcd, lcm;
printf("Enter two positive integers: ");
scanf("%d %d",&n1,&n2);
for(i=1; i <= n1 && i <= n2; ++i) {
printf("Enter two positive integers: ");
scanf("%d %d",&n1,&n2);
if(n1==-1,n2==-1) break;
// Checks if i is factor of both integers
if(n1%i==0 && n2%i==0)
gcd = i;
}
lcm = (n1*n2)/gcd;
printf("The LCM of two numbers %d and %d is %d.", n1, n2, lcm);
return 0;
}
'if(n1 == - 1,n2 == - 1)'您能解释一下吗? – DeiDei
如果你是新手,Stack Overflow可能不适合你。有许多免费的教程资源,你应该花一些时间。一旦你掌握了基本知识,你可能会发现这个网站对于具体的,经过深入研究的问题很有用。 –
break语句在第15行(不是12) - 您确定我们正在查看与您相同的代码吗? –