A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C++ to enter any number and print all factors of the number
Q:

Write a program in C++ to enter any number and print all factors of the number

0

Write a program in C++ to enter any number and print all factors of the number

Sample Output:

 Print all factors of a number:                                        
-----------------------------------                                    
 Input a number: 63                                                    
The factors are: 1 3 7 9 21 63

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;
int main()
{
    int num, i;
    cout << "\n\n Print all factors of a number:\n";
    cout << "-----------------------------------\n";
    cout << " Input a number: ";
    cin >> num;
    cout << "The factors are: ";
    for (i = 1; i <= num; i++) 
    {
        if (num % i == 0) 
        {
            cout << i << " ";
        }
    }
    cout << endl;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now