Thursday, June 13, 2013

C/C++ program to print the divisors of an integer/number in descending order.


#include<iostream>
using namespace std;
int main()
{
        int num , divisor;
        cout<<”Enter the number: “<<endl;
        cin>>num;
        divisor=num;
        if(num<0)
        {
               cout<<”Please enter the positive integer: “<<endl;
         }
         cout<<”The divisors of “<<num<<” are:”<<endl;
         while(divisor>=1)
         {
                if(num%divisor==0)
               {
                      cout<<divisor<<endl;
               }
                divisor–;
        }
        system(“pause”);
}
 

No comments:

Post a Comment