C++ Program to Display Factors of a Number

C++ program to print factors of a number using loop.


C++ Program to find all positive factors of a number

#include <iostream>

using namespace std;  
   
int main() {  
    int i, N;   
    
    cout << "Enter a Number\n";  
    cin >> N;  
   
    cout << "Factors of " << N << endl;  
     
    // Check for every number between 1 to N, 
    // whether it divides N 
    for(i = 1; i <= N; i++) {   
        if(N%i == 0) {  
            cout << i << " ";  
        }  
    }  
   
    return 0;  
}
Output
Enter a Number
50
Factors of 50
1 2 5 10 25 50

Recommended Posts
C++ Program to Find Power of a Number
C++ Program to Convert Decimal Number to Binary Number
C++ Program to Convert Decimal Number to Octal Number
C++ Program to Reverse Digits of a Number
C++ Program to Find Power of Number using Recursion
C++ Program to Find GCD of Two Numbers
C++ Program to Find Factorial of a Number
C++ Program to Find Sum of Natural Numbers
C++ Program to print ASCII Value of All Alphabets
All C++ Programs