C++ Program to Display Factors of a Number

#include<iostream.h>
#include<conio.h>
void main()
{
    int n, i;
    clrscr();
    cout<<"Enter any Positive Integer: ";
    cin>>n;
    cout<<"Factors of "<<n<<" are: "<<endl;
    for(i = 1; i <= n; ++i)
    {
       if(n % i == 0)
          cout<<i<<endl;
   }
getch();
}

OUTPUT:

Enter any Positive Integer: 12
Factors of 12 are:
1
2
3
4
6
12

Sharing Is Caring

Leave a Comment