C++ Online Compiler
Example: Find Factors of a Number C++ using For loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Find Factors of a Number C++ using For loop #include <iostream> using namespace std; int main() { int x, i; cout << "-----Enter the positive integer number-----\n"; cin >> x; cout << "\nThe factors of the " << x << " are: "; for (i = 1; i <= x; ++i) { if (x % i == 0) { cout << i << " "; } } cout << "\n"; return 0; }
86
Output
Clear
ADVERTISEMENTS