Answer to Question #177050 in C++ for Weam Aljayatweh

Question #177050

Q1. Write a C++ program that takes a positive integer number and displays all the factors of that number . Thus, for example , if number ser = 12 , the program will print 1, 2, 3, 4, 6, 12


1
Expert's answer
2021-03-30T18:30:50-0400
#include <iostream>
using namespace std;

int main() {
    int n;

    cout << "Enter a number: ";
    cin >> n;

    for (int i=1; i<=n; i++) {
        if ( n%i == 0) {
            cout << i << " ";
        }
    }
    cout << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS