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<
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
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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
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.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning