Write a C++ Program to Display Factors of a Number

C++ Program to Display Factors of a Number

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ Program to Display Factors of a Number
C++ Program to Display Factors of a Number

Write a C++ Program to Display Factors of a Number

PROGRAM: C++ Program to Display Factors of a Number

/* C++ Program to Display Factors of a Number*/

#include <iostream>
using namespace std;

int main() {
int n, i;

cout << “Enter a positive integer: “;
cin >> n;

cout << “Factors of ” << n << ” are: “;
for(i = 1; i <= n; ++i) {
if(n % i == 0)
cout << i << ” “;
}

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *