1 Star 0 Fork 0

JJustRight/ACM-ICPC-Algorithms

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
All factors of a given Number.cpp 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
BlueFRJ 提交于 2018-10-03 06:06 +08:00 . Create All factors of a given Number.cpp
//We include de I/O library
#include <iostream>
/* We include the stdenteredNumeramespace so we don't have to write std::
Everytime we want to use "cout" or "cin" */
using namespace std;
int main()
{
// We declare our variables
int enteredNumer, i, factorization;
// Ask for a number
cout << "Enter a number of your choice (positive and integeer): ";
// Assing the entered value to the "enteredNumer" variable
cin >> enteredNumer;
cout << "These are the factors for " << enteredNumer << ": " << endl;
factorization = enteredNumer;
// Every number has 1 as it's factor, so we'll say this right away
cout << 1 << endl;
// Check the factors (starting with 2, until the number is reached)
for(i = 2; i <= enteredNumer; ++i)
{
// If the divided number has 0 as the division reminder, it'll be a factor
while (factorization % i == 0){
// Print this number everytime
cout << i << endl;
// As it is a factor, let's divide by it to find the next one!
factorization = factorization / i;
};
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/jjustright/ACM-ICPC-Algorithms.git
git@gitee.com:jjustright/ACM-ICPC-Algorithms.git
jjustright
ACM-ICPC-Algorithms
ACM-ICPC-Algorithms
master

搜索帮助