输出一个数的所有因数

This commit is contained in:
flykhan 2023-06-24 10:19:24 +08:00
parent 6859943be2
commit 5434ce3192
1 changed files with 22 additions and 0 deletions

22
day7/homework/oh1.cpp Normal file
View File

@ -0,0 +1,22 @@
// 输入一个整数,输出它的所有因数。
// 例如:输入 12输出 1 2 3 4 6 12
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "请输入一个整数:";
cin >> n;
int i = 1;
while (i <= n)
{
if (n % i == 0)
cout << i << "\t";
i++;
}
return 0;
}