输入一个n,接下来n行,每行输入一个数做处理。
当我输出n=3
输入第一行时 我输入6
j的那一层循环,j一直停在2是为什么?怎么解决
#include <iostream>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
int x;
for(int i=1;i<=n;i++)
{
cin>>x;
int s=0;
for (int j=1;j<=int(sqrt(x));j++)
{ cout<<j<<endl;
if (x%j==0)
{
if (j=1) s+=1;
else s+=j+s/j;
}
}
if (x==s) cout<<"A";
}
}
18行你写的j=1 这是赋值
应该写j==1,这才是判断
你写了j=1,然后循环j++,变成2,2对2取余为0,又让j=1了,所以死循环了
有用请点个采纳~~
18行 if判断的条件,少了个=符号