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