ng namespace std; int main(int argc, char const *argv[]) {     int n;     cin>>n;     // since the divisors occur in pairs, it is enough to traverse till sqrt(n)     for(int i=1;i<=sqrt(n);i++)     {         if(n%i==0) // check the divisibility         {             if(n/i==i) // if same number appears in the pair, for example for n =100, the number 10 occurs twice. It is enough to print             // it once                 cout<

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

include<cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    // since the divisors occur in pairs, it is enough to traverse till sqrt(n)
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0) // check the divisibility
        {
            if(n/i==i) // if same number appears in the pair, for example for n =100, the number 10 occurs twice. It is enough to print
            // it once
                cout<<i<<" ";
            else // print the divisors
                cout<<i<<" "<<n/i<<" ";
        }
    }
   // The TC . 

 

 

 

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning