C++ 程序中while循环的突然中断,以查找因素
我正在编写一个代码,它使用两个嵌套的While循环计算任意给定数字的两个因子,但是在一次迭代之后,循环就停止了 节目C++ 程序中while循环的突然中断,以查找因素,c++,math,while-loop,nested-loops,computation,C++,Math,While Loop,Nested Loops,Computation,我正在编写一个代码,它使用两个嵌套的While循环计算任意给定数字的两个因子,但是在一次迭代之后,循环就停止了 节目 #include <iostream> #include <conio.h> using namespace std; long int Password; void main() { long int n=2,n1=2; cout<<"Type the number whose factor you need"<&l
#include <iostream>
#include <conio.h>
using namespace std;
long int Password;
void main()
{
long int n=2,n1=2;
cout<<"Type the number whose factor you need"<<endl;
cin>>Password;
while( n < 3600 )
{
while( n1 < 3600 )
{
if( n*n1 == Password )
{
cout<<"your Factors are "<<n<<" and "<<n1<<endl;
getch();
}
else
{
n1++;
break;
}
}
n++;
}
}
#包括
#包括
使用名称空间std;
长整数密码;
void main()
{
长整数n=2,n1=2;
cout您的程序没有计算任何给定数字的因子。此外,将数字命名为“密码”会让人困惑
也许您希望在C++中实现类似的功能:
#include <iostream>
using namespace std;
int main() {
unsigned int number;
cout << "Enter a positive integer whose factors you need: " << endl;
cin >> number;
cout << "Factors of " << number << " are ";
for (int i = 1; i <= number; ++i) {
if (number % i == 0)
cout << i << " ";
}
cout << endl;
return 0;
}
#包括
使用名称空间std;
int main(){
无符号整数;
库特数;
可以编译吗?始终使用大括号-防止errors@EdHeal是的,程序在VS中编译,在Turbo C++中编译< <代码>中断;如果满足条件,则需要运行< /COD>。C++应该是代码> int()
@Vinay5forPrime这不是一个很好的问题。在给出的代码和提出的问题之间几乎没有任何联系。最接近实际问题的是最后一句话,它似乎不知从何而来,在问题的其他部分没有上下文。此外,您也没有在调试程序时表现出任何努力也没有问如何调试它。