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
#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;
}
Comments
Leave a comment