Exercise 4 nested for loops) Write a program that continuously reads two positiv
ID: 3677344 • Letter: E
Question
Exercise 4 nested for loops) Write a program that continuously reads two positive integer numbers, nl and n2, until the u enters a negative number for any input. Your program should print the second factor for eac number between nl and n2. Do not include 1 and the number itself in finding the factors of number CA. C Windows Asystem32cmd.exe Enter two positive numbers 1 and n2 n2 n 2 9 6's second factor is 3 8's second factor is 4 two positive numbers n1 and n2 (n2 n1 5 15 Ente 6 second factor is 3 8's second factor is 4 10's second factor is 5 12's second factor is 3 14's second factor is 7 15's second factor is 5 two positive numbers n1 and n2 (n2 n1 7 23 Ente 8's second factor is 4 10's second factor is 5 12's second factor is 3 14's second factor is 7 15's second factor is 5 16's second factor is 4 18's second factor is 3 20's second factor is 4 21's second factor is 7 22's second factor is 11 Enter two positive numbers n1 and n2 (n2 nl) -1 2 Press any key to continueExplanation / Answer
/* C++ to find and display the second factors between two numbers entered by an user.. */
#include <iostream.h>
using namespace std;
int main()
{
int n1,n2,i;
cout << "Enter two positive numbers n1 and n2 (n2 > n1): ";
cin >> n1 >> n2;
if(n2>n1)
{
if(n1%2==0)
{
for(i=2;i<n2;i++)
{
int count=0;
if(n1%i==0)
{
count++;
if(count==2)
{
cout << n1 << "'s second factor is" << i << endl;
}
}
}
}
else
{
n1++;
}
cout << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.